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

mobx 6 not throwing an error (only warning) if using enforceActions, is this by design? #2417

Closed
johot opened this issue Jul 30, 2020 · 5 comments

Comments

@johot
Copy link

johot commented Jul 30, 2020

It seems mobx 6 will only do a console.warn when using enforceActions. What is the reasoning for this? I loved the fact that it forced me to do things the "correct way" in previous mobx versions :)

If this is intended could an option be added to force it to throw also?

Thank you for all your great work!

@johot johot added the 🐛 bug label Jul 30, 2020
@mweststrate
Copy link
Member

mweststrate commented Jul 30, 2020 via email

@nixaboo
Copy link

nixaboo commented Dec 20, 2021

I would rather it throws, it makes more sense to me-> especially since it actually performs the state change.

For those intrested in a dirty-hack:

let warn = console.warn;
console.warn = (t) => {
if (t.indexOf('[MobX] Since strict-mode is enabled') >= 0) {
throw t;
}

warn(t);

};

It's not ideal but better than forking MobX :)

@mweststrate
Copy link
Member

mweststrate commented Dec 20, 2021 via email

@nixaboo
Copy link

nixaboo commented Dec 20, 2021

Niiice! Didn't know this existed, very useful!

FYI for those doing it as well, edit the files in the dist folder of mobx

@upsuper
Copy link
Contributor

upsuper commented Dec 7, 2022

Hey @mweststrate,

In Canva, we find it hard to enforce this rule across a massive codebase and large number of developers in the organization without having it throw an error. Very few developers and basically no reviewers would notice an extra warning a change introduces if everything else works as expected. So we also want it back to throw an error instead of just issuing a console warning.

I would also argue that if it doesn't interrupt the normal flow, it is not really "enforcing" anything, just warning, so the name of the option is very misleading.

I can see in f60c913, you changed its behavior because you want to make it default without breaking too much existing code that doesn't enforce it currently. However, such change in behavior breaks our reliance on it to actually enforce the rule.

I suggest that a new option should be introduced for the purpose, maybe something like requiresActions to be consistent with other options that warn rather than throw. Alternatively, maybe consider making enforceActions accept more options like { on: 'always' | 'observed', level: 'warn' | 'throw' }, and map the existing string values to be with level: 'warn'.

It would be really unfortunate if we have to patch an actively maintained package like MobX, especially given that we use it in multiple packages.

Could you reconsider the decision?

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

4 participants