-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
log warning or error if duplicate instances of mobx are found #1018
Comments
Ideas welcome! Note that there are 4 different situations
I think we can quite safely deprecate option 2, and don't think about it too much. Option 4 is fine with regards to this idea, as it will result in only a single mobx instance. The trouble then is; how to distinguish situation 1 from situation 3? |
Thanks, I didn't think about 1 (where you might actually want isolation/multiple instances). For distinguishing between 1 vs 3, maybe it should be up to libs to tell mobx whether to warn of duplicate instances. Or just always logging "mobx lib loading" might be enough of a hint for debugging purposes, by making multiple instances more obvious. For now I will try comparing my lib's mobx === client's mobx. thanks! |
So basically we have to do import { Atom, Reaction, extras } from 'mobx'
extras.shareGlobalState() and import { observable, extras } from 'mobx'
import myFancyFunction from 'mobx-fancy-function'
extras.shareGlobalState() Is it possible in future mobx versions to share state in some namespaces instead of only in global? extras.shareState('react', 'router') // internal namespaces, per functionality
extras.shareState('global') // global namespace, main thread of app
extras.shareState('my-own-namespace') // some customized namespaces, for example per framework |
Found a way to properly add the warning, by requiring people to also signal if they want to use mobx in isolation. Version 3.2 will warn about this in the future (if all mobx versions are on 3.2+). Thanks for the suggestion @nyura123 |
I have a:
Question
Issue:
Idea:
Log warning or error if duplicate instances of mobx are found.
Save hours on debugging problems that happen when there are duplicate instances of mobx.
My app and a dependent lib both use mobx. When I
npm link
'd the lib, it resulted in a second instance of mobx being used, causing the app's mobx observables not to be updated when expected.I think so as there are multiple scenarios when duplicate instances of mobx can occur - e.g. Weird bug since 3.x #763, possibly Dynamically imported module in react won't react to Mobx observable #966, Breaks mobx danielearwicker/bidi-mobx#4
Yes. One idea is to set either a
window.__mobxIsFound
orglobal.__mobxIsFound
at the top of mobx lib, and just print a console.error/warning if the flag is already true.Just wanted to bring this up as an idea to see if others might find it useful.
The text was updated successfully, but these errors were encountered: