-
Notifications
You must be signed in to change notification settings - Fork 24
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
mhtml-onmount fires after attaching to the main document dom #57
Comments
@fizzy33 thanks for bringing up the issue! As I've said on gitter, I totally agree these callback should only be called after everything is actually mounted to the dom. For performance reasons, you might also want to do things before node are mounted, to prevent a repaint. But let's keep things minimal until someone comes with a proper use case. Also, it seems that react folks are thinking about removing their componentWillMount callback, so it might be a good idea no to had that too quickly. Fixing this issue properly might require non-trivial refactoring. These are the options I'm currently seeing:
|
Implicit in your statement but worth noting explicitly that this is performance critical code hence even the consideration of the third bullet point. Throwing a fourth option out there. What about attaching the onmount to the dom element and then using a query selector to call them all after mount? |
How would you keep track of the list query selection to use for calls after mount? I think that would still be point 2/3 above... |
Add a data-mhtml-onmount attribute which is the actual function to call. Then later after it is attached to the dom do a document.querySelectorAll("[data-mhtml-onmount]") To get and call all the callbacks. So a philosophical question does mutation count if the browser is doing it for you? |
I see, nice idea, that's indeed a 4th option! It does affect the dom itself, that might not be desirable... |
Agreed on affecting the dom. For me if I have
It isn't completely surprising for me to see that on the in browser dom element. What about removing it once it was run (noting I feel dirty even typing this sentence). |
Something like this:?
Querying over the entire page for a class and iteratively mutating the dom might have a cost that the global mutable list doesn't have... |
Yes with the refinement to query from the mounted element will give better performance. |
Currently onmount fires after the children have been built but before the parent has been attached to the dom. onmount should fire after the parent has been attached.
Various tools (like jquery plugins) rely on being attached to the document dom. This will make integrating with jquery much simpler.
I would suggest the scaladoc be updated to reflect this. Time permitting I will provide a pull request with this change and the scaladoc update.
As a temporary workaround use
This works since it fires in a later event loop cycle and hence after the attach happens.
The text was updated successfully, but these errors were encountered: