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

handle moving nodes #382

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

handle moving nodes #382

wants to merge 3 commits into from

Conversation

mdynnl
Copy link
Contributor

@mdynnl mdynnl commented Nov 11, 2024

@@ -460,7 +460,6 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
if (value === current) return current;
const t = typeof value,
multi = marker !== undefined;
parent = (multi && current[0] && current[0].parentNode) || parent;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what might break by this removal but this for sure breaks the parent comparison in cleanChildren

Copy link
Contributor

Choose a reason for hiding this comment

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

Ryan made a comment about this code in a related issue here #307 (comment)
I will have to study it again to refresh my mind, I'm not sure I actually ever understood that part

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tried to track this down and, oh well 😅, no wonder even Ryan can't remember this. This check existed since the beginning.

Comment on lines 575 to 578
if (!moved) {
moved = new WeakSet();
queueMicrotask(() => (moved = null));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

WeakSet is already used by hydration so doesn't hurt anything but there might be better approaches than this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest considering a strong referenced array to be cleared in the microtask as moved.length = 0. As the cost of instantiating could be removed, and also a set will try to deduplicate the nodes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking if weakset was faster than array to check for element existence. Any form of book-keeping works really. We could also keep it in the nodes but I don't know the performance side of this. Essentially we need to know if a node has changed position in the tree.

Copy link
Contributor

@titoBouzout titoBouzout Nov 15, 2024

Choose a reason for hiding this comment

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

Makes sense. Last time I measured this, for a fairly low amount of items there was no significant difference between [].includes and set.has and you do not pay the cost of the Set having to deduplicate/hash items. I think solid reactivity does this (ex: reading a signal just pushes to observers without deduplicating).

At first sight sounds like keeping the info in the node will complicate the logic, either a microtask for each node or some sort of counter. Probably worth considering, as a microtask could introduce desync, not sure if solidjs/signals will use microtasks, but everything becomes a race when used. This is why I do not like reactivity in microtasks

Maybe make of the WeakSet a Set to be hold in the parent scope, and call set.clear() in the microtask. I'm thinking of at least not paying the cost of creating the set/array each time.

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.

Cannot reuse a dom element when switching mount locations
2 participants