react-native-fabric icon indicating copy to clipboard operation
react-native-fabric copied to clipboard

Answers.logCustom is making objects Immutable

Open braco opened this issue 7 years ago • 1 comments

Made a redux middleware logger for this package, and is breaking from modifying the object to be Immutable:

const reduxLogMiddleware = store => next => action => {
  // This is the equivalent of Answers.logCustom('name', { ... })
  Answers.logCustom(action.type, action);
  return next(action);
};

This will throw an error deeper in the application, as action is modified to become immutable:

 Error: You attempted to set the key ... with the value ... on an object that is meant to be immutable and has been frozen.
    at throwOnImmutableMutation

which is probably from here react-native/Libraries/BatchedBridge/MessageQueue.js

Is there any way to avoid this without making clones of every logged object? This fixes the problem, but is not ideal:

Answers.logCustom(action.type, Object.create(action));

braco avatar Jun 30 '17 19:06 braco

That would be the solution in this case, this seems more like a redux issue than an issue with this module as all we are doing is sending the object across the bridge.

The only other option would be to clone the object in https://github.com/corymsmith/react-native-fabric/blob/master/Answers.js but may be overkill since it only seems to affect users using redux / immutable.

corymsmith avatar Aug 02 '17 21:08 corymsmith