relay-tools / react-relay-network-layer

ReactRelayNetworkLayer with middlewares and query batching for Relay Classic.
MIT License
277 stars 47 forks source link

One of the sources for assign has an enumerable key on the prototype chain #60

Closed jamesone closed 6 years ago

jamesone commented 6 years ago

I'm getting the following error when trying to use this package on react-native (0.55.4):

ExceptionsManager.js:71 Unhandled JS Exception: One of the sources for assign has an enumerable key on the prototype chain. Are you trying to assign a prototype property? We don't allow it, as this is an edge case that we do not support. This error is a performance optimization and not spec compliant.

The simulator is throwing the following error:

github screenshot 2018-06-05 17 49 09_preview

You can see the simulator is referencing fetchWithMiddleware.js (line: 41-13)

Any ideas why this is happening? I've looked everywhere to try and find a solution, none of them work.

I believe it has something todo with a middleware I added, however, commenting this out doesn't fix the error:

let headers = {
x: 'y',
z: 'x',
};

...otherMiddlewares
next =>
        req => {
          Object.assign(req.headers, headers);
          return next(req);
        },
nodkz commented 6 years ago

Try to do it in such way:

req.headers = Object.assign({}, req.headers, headers);
jamesone commented 6 years ago

This didn't seem to fix the error. I don't think it's related to the code snippet above ^ 🤔 I commented it out & the error remains.

jamesone commented 6 years ago

After investigating this further, I found that removing Object.assign on line 7 in fetchWithMiddleware fixes the error.

var _extends = function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

I think this is an issue with react-native not allowing the use of Object.assign in certain scenarios.


How can I go about creating a patch for this?

jamesone commented 6 years ago

I had to add the following to fetchWithMiddleware.js:

function extend(target) {
  for (var i = 1; i < arguments.length; i++) {
    var source = arguments[i];
    for (var key in source) {
      if (Object.prototype.hasOwnProperty.call(source, key)) {
        target[key] = source[key];
      }
    }
  }
  return target;
};

I then had to use it here:

return extend({}, res, { payload: payload }); Inside the runFetch method