-
-
Notifications
You must be signed in to change notification settings - Fork 927
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
Double initialization of mounted component #1763
Comments
i think m.redraw on init is okay because of xhr request.. unless mithril will have to put restriction on making an xhr request on init.. |
I think m.redraw's from any callback seems to be fine. doing setTimeout(() => {m.redraw()}, 0) instead doesn't make the main component reinitialize. I can really not think of any case where you'd want to call m.redraw directly in any oninit function, so this might not be a problem really. The only thing is that if you do it by mistake (like I did) it can take a long time to debug |
For me it was very confusing when in the end I brought out the axe and just removed huge parts of the code until I could narrow it down. Since it also depends on the current execution speed each time, it might happen but it might also be completely fine |
The problem comes from the fact that The "heavy" work causes the #1592 starts to address this, but more work is needed, as discussed there. |
So, I did something stupid and found a very weird edge case. Basically I mounted a component and in a subcomponents oninit function I had a call to m.redraw.
Turns out, if you do some 'heavy' work in your mounted component, and do a m.redraw in a subcomponent to it, mithril will initialize the maincomponent twice (also, it will be very confused about state and stuff)
I cut it down to this fiddle https://jsfiddle.net/v6tx4tLk/13/ so you can have a look.
While you should probably never have a m.redraw in an oninit function (can't think of a valid case for this right now at least), it's definitely something you can do by mistake. And this bug was really hard to track down
The text was updated successfully, but these errors were encountered: