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

Detect opportunity to insert new vnode earlier for more efficient DOM manipulation #1106

Merged
merged 1 commit into from Jan 31, 2024

Conversation

paldepind
Copy link
Member

This changes the child reordering patch process slightly. Before beginning to move elements around we add an extra case where we check if the end of the new remaining vnodes is brand new and could thus be handled by inserting a new DOM node.

This should address and close #1099.

insertCount++;
htmlDomApi.insertBefore(a, b, c);
}
};
Copy link
Member Author

Choose a reason for hiding this comment

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

This change has no effect on the resulting DOM, only on the process by which we get there. Hence the test wraps the htmlDomApi to be able to observe what goes on in there.

@@ -837,6 +838,44 @@ describe("snabbdom", function () {
assert.equal(elm.children[1].innerHTML, "symbol");
assert.equal(elm.children[2].innerHTML, "symbol");
});
it("simultaneous addition in beginning and removal in end", function () {
Copy link
Member Author

Choose a reason for hiding this comment

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

This test also passed before this PR. I'm adding it for symmetry with the test below and to make sure that the non-inefficent case reported in #1099 is now tested.

@@ -49,7 +49,7 @@ function isDocumentFragment(
return api.isDocumentFragment!(vnode as any);
}

type KeyToIndexMap = { [key: string]: number };
Copy link
Member Author

Choose a reason for hiding this comment

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

This is unrelated to the PR but I just happened to improve this type as well.

@paldepind paldepind changed the title Detect opportunity to insert new vnode earlier for more efficientt DOM manipulation Detect opportunity to insert new vnode earlier for more efficient DOM manipulation Jan 31, 2024
@paldepind paldepind merged commit 4383817 into master Jan 31, 2024
3 checks passed
@paldepind paldepind deleted the detect-more-inserts branch January 31, 2024 09:05
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.

Virtualized list issue
1 participant