Skip to content
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

Fix broken order of nodes during hydration #6283

Closed
wants to merge 3 commits into from

Conversation

haveyaseen
Copy link
Contributor

Fix #6279

Not sure exactly why this works but it does fix the issue for me. Need to add tests.

@@ -22,7 +22,7 @@ export function append(target: Node, node: Node) {
if (is_hydrating) {
nodes_to_detach.delete(node);
}
if (node.parentNode !== target) {
if (node.parentNode !== target || node.parentNode !== null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm..reading from face value, this doesn't seems like a correct fix, there's maybe something wrong earlier in the hydration process / rather in the append method.

adding || node.parent !== null seems to defeat the purpose of doing node.parentNode !== target check

Copy link
Member

@benmccann benmccann May 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would defeat the check and so I agree the code shouldn't be written this way. It's also worth noting though that the check was introduced along with the bug in #6204 so we may not need to keep the check as is. If you remove this check and the one in insert to go back to how the code was originally then the tests will still pass. I don't think that either change would be the correct change though. The tests all pass with either change, which probably shows a shortcoming in the tests

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the alternate of this is

if (node.parentNode !== target || node.nextSibling !== null) {

taking care the case where node parent is already correct, but the order is wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In insert the following passes as well:

if (
	node.parentNode !== target ||
	(!anchor && node.nextSibling !== null) ||
	(anchor && node.nextSibling !== anchor)
) {

Definitely looks much more sensible than my initial attempt, although I don't know there still are other edge cases not caught by the tests. Would there be any good way to test the idempotence property more directly?

@benmccann
Copy link
Member

Thanks for the PR. The test was merged in #6290, so I'm going to close this. The fix probably isn't the right one according to the description in #6279 (comment)

@benmccann benmccann closed this May 3, 2021
@haveyaseen haveyaseen deleted the hydrate-order branch May 3, 2021 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nodes appear out of order on hydration with 3.38.1
3 participants