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 hydrating top level content #4550

Merged

Conversation

tanhauhau
Copy link
Member

@tanhauhau tanhauhau commented Mar 13, 2020

Fixes #4542

Explanation: #4542 (comment)

@Conduitry
Copy link
Member

The node claiming process doesn't result in the DOM using any of the same nodes as it initially had (which would then get removed by nodes.forEach(detach))?

@tanhauhau
Copy link
Member Author

The node claiming process doesn't result in the DOM using any of the same nodes as it initially had (which would then get removed by nodes.forEach(detach))?

Not sure I get the question.. yes we need to remove nodes in the initial DOM that are not claimed.

@Conduitry
Copy link
Member

What I meant was wouldn't the claimed nodes still be there in the nodes array, and that we wouldn't actually want to remove them after claiming?

@tanhauhau
Copy link
Member Author

tanhauhau commented Mar 14, 2020

oh, when we found a match in the nodes array, we removed them, see

nodes.splice(i, 1)[0];

in

export function claim_element(nodes, name, attributes, svg) {
for (let i = 0; i < nodes.length; i += 1) {
const node = nodes[i];
if (node.nodeName === name) {
let j = 0;
while (j < node.attributes.length) {
const attribute = node.attributes[j];
if (attributes[attribute.name]) {
j++;
} else {
node.removeAttribute(attribute.name);
}
}
return nodes.splice(i, 1)[0];
}
}

@Conduitry
Copy link
Member

Ah gotcha, I hadn't noticed that during the claim, the array gets mutated. Thanks.

@Conduitry Conduitry merged commit ec3589e into sveltejs:master Mar 14, 2020
taylorzane pushed a commit to taylorzane/svelte that referenced this pull request Dec 17, 2020
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.

Top-level raw {@html} hydrated incorrectly
2 participants