Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strict mode failed even though code already wrapped in actions. #866

Closed
5 of 11 tasks
BananaCloud opened this issue Mar 3, 2017 · 2 comments
Closed
5 of 11 tasks

Comments

@BananaCloud
Copy link

Welcome to MobX. Please provide as much relevant information as possible!

Hi, I'm trying to do what this code does:
https://github.com/meteor-space/tracker-mobx-autorun/blob/master/observe-cursor.js
This used to work fine with MobX 2.x version. I'm trying to bridge between MeteorJS's Trackr to Mobx by clone the code above. I've only bumped up the MobX version to the latest 3.1.2 without further changes. I'm getting this error below, even though the observable modification is clearly wrapped by an action. I've tried to do some debugging myself, and found that

in this function:
function checkIfStateModificationsAreAllowed(atom) {
var hasObservers = atom.observers.length > 0;
if (globalState.computationDepth > 0 && hasObservers)
fail(getMessage("m031") + atom.name);
if (!globalState.allowStateChanges && hasObservers)
-->> fail(getMessage(globalState.strictMode ? "m030a" : "m030b") + atom.name);
}

globalState.allowStateChanges will always be false. Without too much of the internal knowledge of MobX. I can't proceed any further.

Exception in queued task: Error: [mobx] Invariant failed: Since strict-mode is enabled, changing observed observable values outside actions is not allowed. Please wrap the code in an action if this change is intended. Tried to modify: ContactsState@3._contacts
at invariant (eval at (http://localhost:3500/assets/web.js:846:2), :2715:15)
at fail (eval at (http://localhost:3500/assets/web.js:846:2), :2710:5)
at checkIfStateModificationsAreAllowed (eval at (http://localhost:3500/assets/web.js:846:2), :989:9)
at ObservableArrayAdministration.spliceWithArray (eval at (http://localhost:3500/assets/web.js:846:2), :1646:9)
at ObservableArray.splice (eval at (http://localhost:3500/assets/web.js:846:2), :1793:27)
at Object. (http://localhost:3000/packages/bananacloud_tracker-mobx-autorun.js?hash=fed5878c2c6a58579ec1dec60e5122ef936d4659:169:25)
at executeAction (http://localhost:3000/packages/modules.js?hash=01e91f6793dd58f999b0889352b4035cce995c71:31446:19)
at Object.res [as addedAt] (http://localhost:3000/packages/modules.js?hash=01e91f6793dd58f999b0889352b4035cce995c71:31437:16)
at LocalCollection._CachingChangeObserver.addedBefore (http://localhost:3000/packages/minimongo.js?hash=68d94baf766fd5bcc86fc44a6758779727eb60f8:3549:28)
at Object.addedBefore (http://localhost:3000/packages/minimongo.js?hash=68d94baf766fd5bcc86fc44a6758779727eb60f8:3484:56)

versions:
Meteor: 1.4
Node: v4.7.3
Browser: Any (I'm using Chrome)
MobX: 3.1.2

I have a*:

  1. Question: Feel free to just state your question. For a quick answer, there are usually people online at our Gitter channel
  2. Issue:
  • Provide error messages including stacktrace
  • Provide as much relevant code, or, preferrably create a reproduction based on this JSFiddle:
  • Did you check this issue wasn't filed before?
  • Elaborate on your issue. What behavior did you expect?
  • State the versions of MobX and relevant libraries. Which browser / node / ... version?
  1. Idea:
  • What problem would it solve for you?
  • Do you think others will benefit from this change as well and it should in core package (see also mobx-utils)?
  • Are you willing to (attempt) a PR yourself?

Please tick the appropriate boxes. Feel free to remove the other sections.

@BananaCloud
Copy link
Author

Update: when I use isAction() imported from mobx to test the extracted action function from the original code, it's return as true.

@BananaCloud
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant