goatslacker / alt

Isomorphic flux implementation
http://alt.js.org/
3.45k stars 322 forks source link

React Native views error on Store changes #649

Open erdostom opened 8 years ago

erdostom commented 8 years ago

I have an app that was working fine until I upgraded React and React-Native.

Now, when state is updated with onChange, I see the following error (even if there is no actual change in state, the Store was just subscribed to an event).

Unhandled JS Exception: One of the sources for assign has an enumerable key on the prototype chain. This is an edge case that we do not support. This error is a performance optimization and not spec compliant.

My versions:

"alt": "^0.18.4",
"react": "15.0.2",
"react-native": "^0.26.2",
hainuo commented 8 years ago

so do i。

Possible Unhandled Promise Rejection (id: 0):
One of the sources for assign has an enumerable key on the prototype chain. This is an edge case that we do not support. This error is a performance optimization and not spec compliant.
TypeError: One of the sources for assign has an enumerable key on the prototype chain. This is an edge case that we do not support. This error is a performance optimization and not spec compliant.
    at Object.assign (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:266:7)
    at ReactCompositeComponentWrapper._processPendingState (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:23475:1)
    at ReactCompositeComponentWrapper.updateComponent (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:23434:20)
    at ReactCompositeComponentWrapper.wrapper [as updateComponent] (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:11526:13)
    at ReactCompositeComponentWrapper.performUpdateIfNecessary (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:23384:6)
    at Object.performUpdateIfNecessary (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:21734:18)
    at runBatchedUpdates (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:21385:17)
    at ReactNativeReconcileTransaction.perform (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:22051:12)
    at ReactUpdatesFlushTransaction.perform (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:22051:12)
    at ReactUpdatesFlushTransaction.perform (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:21331:34)

you can checkout branch getstartalt of https://github.com/pingang360/alt-pgw.git to Repeat this error

  "dependencies": {
    "alt": "^0.18.4",
    "react": "15.0.2",
    "react-native": "^0.26.1",
    "react-native-navigator-router": "^0.2.0",
    "react-router": "^2.5.2"
  }
adriansdev commented 8 years ago

React no longer allows you to set state properties which were not declared in the constructor.

edgeadjei commented 7 years ago

@adriansprod could you please elaborate.

I've initialized my constructor and declared my default state but i'm still receiving the same error.

application.store.js

import alt from "../alt.js";
import applicationActions from "../actions/application.actions.js";

class applicationStore {
  constructor() {
    this.selectedClient = {};
    this.bindAction(applicationActions.setClient, this.setClientHandler);
    ...
  }
  setClientHandler(client){
   // {_id:  clientId, name:  clientName}
    this.selectedClient = client;
  }
  ...
}

export default alt.createStore(applicationStore, "applicationStore");

application.actions.js

import alt from "../alt.js";

class applicationActions {
  setClient(client){
    return client;
  }
  ...
}

export default alt.createActions(applicationActions);

Error

11-14 18:29:44.628 11790 15091 W ReactNativeJS: { [TypeError: One of the sources for assign has an enumerable key on the prototype chain. This is an edge case that we do not support. This error is a performance optimization and not spec compliant.]
camwhite commented 7 years ago

I too am seeing this after updating RN, any clarification on resolving this would be much appreciated.

avdept commented 7 years ago

Any progress on this?

erdostom commented 7 years ago

I ended up just moving to redux..

On Mon, Mar 6, 2017 at 10:50 AM, Alex Sinelnikov notifications@github.com wrote:

Any progress on this?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/goatslacker/alt/issues/649#issuecomment-284436420, or mute the thread https://github.com/notifications/unsubscribe-auth/ADkk03AMngouCGpHgqh2BUo9qfiatFNjks5rjCs2gaJpZM4IpKDX .

avdept commented 7 years ago

I was able to fix it by explicitly assigning values from incoming object to state.

anarqz commented 6 years ago

@avdept did you find out any other solution than this?

repetitions commented 6 years ago

@camwhite @alcmoraes

Some additional clarification:

Because of this performance optimization change in React Native, you won't be able to define instance variables in the store directly anymore. The workaround would be to declare and use your variables in this.state in your stores.

So, in your store, instead of

this.myVariable = value;

do this:

this.state = { myVariable: value };