-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(native-dom): clear node_id_mapping when nodes are removed #5182
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
base: main
Are you sure you want to change the base?
fix(native-dom): clear node_id_mapping when nodes are removed #5182
Conversation
250a884 to
719a663
Compare
|
Hmm.... I think as-is this will leak nodes. Because we're relying on set_id_mapping to clean them up when it replaces a mapping. This is intended to match the behaviour of the interpreter in dioxus-web |
1 similar comment
|
Hmm.... I think as-is this will leak nodes. Because we're relying on set_id_mapping to clean them up when it replaces a mapping. This is intended to match the behaviour of the interpreter in dioxus-web |
The `assign_node_id` function had cleanup logic that called `remove_node_if_unparented` on any existing mapping. This caused panics when a stale mapping pointed to a NodeId that had been reused by the slab for a newly created node that was still on the stack (unparented). The cleanup would incorrectly remove the new node, and later operations trying to use that stack node would panic with "invalid key". Instead, we can greedily gc with `remove_and_drop_node`.
719a663 to
4e2ebbb
Compare
|
Thanks! Yeah that makes sense, I figured this wouldn't be the real solution. How do you feel about immediately gcing the nodes on delete (like this)? I'm pretty sure this is still not the actual bug (when/if this moves to an actual gc) but it does hide it. Not ideal :( I can spend more time thinking about what to do in a bit. |
It was a while ago now, but I'm pretty sure that's how I originally implemented this, but we ended up with the current solution because this was causing panics. IIRC the reason was that Dioxus Core expects the underlying DOM node to stick around for longer so that it can reuse those DOM nodes rather than creating new ones (as a performance optimisation). I think some careful testing is warranted here. Including with example code that creates nodes, then deletes them, then recreates them (todomvc should work I think). Also, do you have a stack trace for the panic you are trying to fix here? |
|
Yep, although I think the stack trace was pretty unhelpful when I was debugging this: I'm happy to pull up any related state in LLDB (I can reproduce this like 30% reliably/nondeterministically with my entire app) if it helps. |
NOTE: I wasn't able to write a minimal reproducer, but this was the problem
I observed in LLDB. Applying this change fixed the
panic!()in my app. Idon't really understand if there's supposed to be a mechanism to avoid this race.
When
remove_nodeorreplace_node_withremoves a node from the DOM, thecorresponding entry in
node_id_mappingwas not being cleared.This is normally fine if
set_id_mappingis called, but if this races withremove_node_if_unparentedthen the app will panic.