Rxjs: AjaxTimeoutError/setPrototypeOf causes fatal crash on Android (React-Native)

Created on 23 May 2018  路  8Comments  路  Source: ReactiveX/rxjs

RxJS version:
6.0.0

Code to reproduce:
I don't have a proper code example, since this is manifesting itself in particular error/network conditions. It seems to happen for any timeout error on a React Native Android APK that is using rxjs/ajax under the hood.

Expected behavior:
Error processed and handled gracefully.

Actual behavior:
Fatally crashing app.

Additional information:

TypeError: undefined is not a function (evaluating 'Object.setPrototypeOf(n,r.prototype)')
  at AjaxTimeoutError(node_modules/rxjs/internal/observable/dom/AjaxObservable.js:392:22)
  at arguments(node_modules/rxjs/internal/observable/dom/AjaxObservable.js:434:28)
  at listener(node_modules/raven-js/src/raven.js:368:71)
  at invariant(node_modules/event-target-shim/lib/event-target.js:171:37)
  at value(node_modules/react-native/Libraries/Network/XMLHttpRequest.js:204:5)
  at XMLHttpRequest(node_modules/react-native/Libraries/Network/XMLHttpRequest.js:433:42)
  at arguments(node_modules/react-native/Libraries/Network/XMLHttpRequest.js:589:18)
  at _lastFlush(node_modules/react-native/Libraries/vendor/emitter/EventEmitter.js:181:40)
  at flushedQueue(node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:357:10)
  at _inCall(node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:119:17)
  at flushedQueue(node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:318:12)
  at value(node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:119:17)

This is related to the use of Object.setPrototypeOf in the AjaxObservable file. Android/RN does not provide this polyfill, so we need to include it ourselves.

Similar issue in apollo-client

There was a mention of IE10 and below needing this polyfill in the 6.0.0-alpha.1 breaking changes, however this wasn't very easy information to find, nor did it cover this particular crash case. If nothing else, I hope this issue can be useful to someone else who runs into it.

Most helpful comment

@tuomohopia We got around this by including the polyfill from mdn.

So inside our index.js file we have:

import React from 'react';
import { AppRegistry } from 'react-native';
import App from './src/App';

Object.setPrototypeOf =
  Object.setPrototypeOf ||
  function(obj, proto) {
    obj.__proto__ = proto;
    return obj;
  };

export default class OurApp extends React.Component {
  render() {
    return <App />;
  }
}

AppRegistry.registerComponent('ourApp', () => OurApp);

All 8 comments

Did you actually manage to sort this issue out anyhow? I keep hitting the same problem, as outlined here:
https://github.com/ReactiveX/rxjs/issues/3878

@tuomohopia We got around this by including the polyfill from mdn.

So inside our index.js file we have:

import React from 'react';
import { AppRegistry } from 'react-native';
import App from './src/App';

Object.setPrototypeOf =
  Object.setPrototypeOf ||
  function(obj, proto) {
    obj.__proto__ = proto;
    return obj;
  };

export default class OurApp extends React.Component {
  render() {
    return <App />;
  }
}

AppRegistry.registerComponent('ourApp', () => OurApp);

@ksaldana1 Thanks a lot!

It indeed does seem to be fixed just with that, except for the custom timeout that I set does not seem to take effect.

@ksaldana1 That worked for me too, thanks!

Thanks @ksaldana1

I was on the verge of switching to Axios. Super weird but, wonder why they haven't fixed it yet. Without this workaround, rxjs ajax package is rendered not working.

@spock123 Glad the fixed helped.

This is honestly more of an issue with the JavaScript environment bundled with the Android runtime environment in React Native than it is an RxJS issue. setPrototypeOf is widely available across modern browsers, so I agree with the RxJS team's decision to remove it as a documented breaking change in v6.

The polyfill approach will have to do for now until the JSC is upgraded.

I would suggest we close this issue as I do not see anything actionable needing to happen in this repo.

@ksaldana1 thanks for the information - interesting. Yes, definitely I think this can be closed now. Thanks again.

it's bit late but yes, our supported target is browser > IE which all have setPrototypeOf support. If runtime doesn't support it, it may need to be polyfilled.

Was this page helpful?
0 / 5 - 0 ratings