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
Fixed rare issue with components initialization #292
Conversation
Yep, fully aware of microtasks etc. The only thing I could recommend trying is removing batching and setTimeout, but that'd have adverse affects on peformance most probably because batching helps to eliminate unnecessary ops iirc. |
// trigger mutation observer event on subtree changes when component add siblings on `attached` | ||
// lifecycle hook. This could lead to issue with components initialization placed at the end | ||
// of childNodes list because they will be out of range of cached length value. | ||
for (var a = 0; a < elements.length; a++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only gripe here is that it's cheaper in IE9 to save elements.length
as elementsLen
in super massive doms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I guess we can't do that :(. I wonder what the performance would be like now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is super massive DOM trees are real world scenario or just synthetic test case?
Do you think we'll need to do anything in |
Couple more questions:
I'm not overly concerned about it, but it'd be interesting to see if this affects IE performance. |
I think what you're experiencing in not being able to reproduce it might be because of fastdom. I'm not certain, but in order to batch dom mutations it'd have to override internal methods. It's probably delaying those which would mean you're right int that it becomes out of sync. You might be able to reproduce it by delaying an appendChild. |
Good morning. Yes i want to put this PR on hold until i finish my investigations. I hope i will complete them in 2-3 hours |
I think the problem was not with
I should notice that this problem take place because there were no other changes in DOM tree |
This PR fix my issue but it is more hack then a proper fix. That is why I want to look into MutationObserver shim |
Well... the problem is not with
Second way is more performant then freezing. |
Updated comment and i think this fix is the best from performance point of view. But always open to discuss other ways to fix this problem. |
👍 let me know when you're ok for this to be merged. Are you able to check to see if this needs fixing on master? I'm happy if you just spot the part in master that needs changing rather than trying to integrate master to where you're reproducing the issue. |
Our QA team is still testing this fix. I'll post results here when they are done. Later will check master branch if it is need to be fixed ;) |
Let me know when I can merge this :) |
Our QA team gives green light to this fix. You can merge it ;) |
Fixed rare issue with components initialization
Created issues for master and the mutation observer polyfill repo. |
Checking master for possible changes right now. Going to create PR soon |
Fixed issue with componentes initialization described in #292
Found today problem with rendering simple DOM tree in browsers that doesn't support custom-elements natively (all except Google Chrome).
DOM tree example
Last
<component2>
node that was not initialized after appending to document. Problem was withMutationObserver
shim that was not firing event on appending child nodes tosection.some-class2
.I was trying to recreate issue in tests with simple DOM manipulations but with no luck.
MutationObserver
shim was working properly.So here is a list of circumstances that could lead to this problem:
<component2>
onattached
callback moves some child nodes tocomponent2.nextSibling
. This behaviour is similar to<label>
element that move inappropriate elements away.P.S. I will continue my attempts to reproduce this problem in tests. But for now i wasn't be able to do this
I guess my problem is related with this line of code that can lead to increasing elements length. Need to investigate... maybe there should be another fix...
If i am right the problem is in this line of code. Because
MutationObserver
callback is synchronously fired before cleaninglastBatchedRecord
this could lead to adding other nodes exactly like in case i faced today. Native MutationObserver callbacks are fired at the "end of micro-task" (there is a good explanation in this article) and i am afraid can't be achieved properly withsetTimeout
. Only promises behave same way but that is not an option for browsers that does not have support for them.Will make another fix tomorrow.