qiniu / formstate-x

Manage state of form with ease.
https://qiniu.github.io/formstate-x
MIT License
34 stars 10 forks source link

Debug error in MobX strict-mode #14

Closed nighca closed 4 years ago

nighca commented 4 years ago

In #13 we replaced options.delay of MobX reaction with our own debounce realization, which caused that the effect will be run outside the effect handler of MobX reaction. So we need to wrap the effect with runInAction, or we got error in projects with strict-mode enabled:

mobx.module.js?daf9:92 Uncaught 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: FieldState@183._validateStatus
    at invariant (mobx.module.js?daf9:92)
    at fail (mobx.module.js?daf9:87)
    at checkIfStateModificationsAreAllowed (mobx.module.js?daf9:746)
    at ObservableValue.prepareNewValue (mobx.module.js?daf9:1057)
    at ObservableObjectAdministration.write (mobx.module.js?daf9:4045)
    at FieldState.set [as _validateStatus] (mobx.module.js?daf9:4209)

In addition, we enabled strict-mode before our test cases, so that we can find such error when running unit test next time.