kitze / mobx-router

A simple router for MobX + React apps
509 stars 66 forks source link

`beforeEnter` can't return `true` when mobx strict-mode is enabled #71

Closed elilambnz closed 5 years ago

elilambnz commented 5 years ago

MobX reports that the route is being updated outside of an @action, error on line 64:

transaction(() => {
    this.currentView = view;
    this.params = toJS(paramsObj);
    this.queryParams = toJS(queryParamsObj);
});

mobx-router version 0.0.17

Full error from the console:

action 'goTo' 
mobx.module.js:98 Uncaught (in promise) Error: [mobx] 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: RouterStore@4.currentView
    at invariant$$1 (mobx.module.js:98)
    at fail$$1 (mobx.module.js:93)
    at checkIfStateModificationsAreAllowed$$1 (mobx.module.js:1088)
    at ObservableValue$$1../node_modules/mobx/lib/mobx.module.js.ObservableValue$$1.prepareNewValue (mobx.module.js:695)
    at ObservableObjectAdministration$$1../node_modules/mobx/lib/mobx.module.js.ObservableObjectAdministration$$1.write (mobx.module.js:3553)
    at RouterStore.set [as currentView] (mobx.module.js:3776)
    at router-store.js:178
    at transaction$$1 (mobx.module.js:2616)
    at RouterStore._callee$ (router-store.js:177)
    at tryCatch (runtime.js:62)
    at Generator.invoke [as _invoke] (runtime.js:296)
    at Generator.prototype.(anonymous function) [as next] (http://localhost:8001/static/js/bundle.js:138587:21)
    at step (asyncToGenerator.js:17)
    at asyncToGenerator.js:28
elilambnz commented 5 years ago

70