-
-
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
Dynamically imported module in react won't react to Mobx observable #966
Comments
@sgus May be you can try this:
because may be MobX only collect dependences which appearance in the |
@suprise Thank you for replying, At first i see it logs "Object {$mobx: ObservableObjectAdministration}" and the same in my asyncedModule and then the wrapper component rerenders (because the action to get the data is asynchronous) and console logs the correct object, but i don't see any render from the asyncedModule. I hope i gave you an idea. |
@sgus are you sure mobx is not bundled into your splitted bundle as well? Like react, mobx should be unique to be able to operate! |
Othwerise, please provide a minimal reproduct repo |
Hi @mweststrate thank you very much for taking the time again. Basically, i have a store with an observable called id, with initial value 3, when you press the button (there is only one button) i load the asynced module which the id, and i update the observable after 3 seconds. I hope i make sense! |
Just looked at your example. Your problem does not relate to mobx. The problem is that in App you just render |
I load a react component dynamically (via webpack's import('module').then) into my bundle. The problem is that the component won't react to Mobx observable's changes. If i import the module the normal way everything works as intended.
Looking at Mobx dev tools i can see that when the component is statically imported, when the observable changes i see that the component re-renders:
Updated ‘[email protected]’: ([email protected]) (was ([email protected])) Scheduled async reaction ‘Reviews#0.render()’ Reaction ‘$Reviews#0.render()’
In contrary when i use code splitting i don't see any render invoked:
Updated ‘[email protected]’: ([email protected]) (was ([email protected]))
Bellow is my code with test data
`class ReviewsStore { // My store
@observable profile = {};
}
@observer class Reviews extends Component { // My View
constructor() {
super();
this.getProfile = this.getProfile.bind(this);
this.state = {
asyncModule: null,
};
}
}`
I'd be grateful for some help, i've been struggling with this issue for more than a week. Thank you in advance!
The text was updated successfully, but these errors were encountered: