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
Bug - Morph text nodes. #2524
Bug - Morph text nodes. #2524
Conversation
currentFrom = dom(currentFrom).nodes().next() | ||
currentTo = dom(currentTo).nodes().next() |
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.
Not relevant to this bug but I believe it's a typo as nodes should be a function call
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.
Good call, should be yeah
Totally dumb question, but I just learned about https://developer.mozilla.org/en-US/docs/Web/API/Document/createTreeWalker. Would that be useful for the traversals or is it not relevant? |
I don't know, i never used it. it would change the original implementation quite a lot so you need to ask Caleb. |
Great question @carlmjohnson! When I cracked into this problem I started there, but there are two problems with TreeWalker: |
currentTo = currentTo && dom(currentTo).nodes().next() | ||
currentFrom = currentFrom && dom(currentFrom).nodes().next() |
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.
Relevant change. When getting the next element for the next loop iteration, we want to use nodes() so we don’t skip text nodes.
Thanks @SimoTod! |
patchChildren uses
firstChild
to select the first child node which works correctly with DOM elements and text nodes but then it usesnextElementSibling
to get the next node which only returns DOM elements. As a consequence, if the children list is a mix of DOM elements and text nodes (for example, a paragraph content with<br>
tags), any text node that is not the first child will be ignored and left in the previous status.Flagged by #2463
Failing test: https://github.com/alpinejs/alpine/runs/4619366189?check_suite_focus=true#step:6:1106