Lock on the cleanNode function #2062
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
It is possible for
cleanNodeto be called recursively. This PR adds a simpleisCleaninglock to ensure thatcleanNodeisn't called on the same node twice.Minimal example: https://playground.solidjs.com/anonymous/9f860e26-d0a3-476d-8b20-82ebff4763d7 (when you click "hide", you get a
Cannot read properties of nullerror which comes fromcleanNodebeing called twice on the same node).I believe this error is most likely to happen when your entire app isn't in Solid, but you're instead mounting several Solid roots inside an existing application. We have global state controlling which Solid roots and components to show, and a
syncStatefunction that reads from the global state and disposes/creates Solid roots based on that. If componentAhas aShowthat causes componentBto be disposed, and componentBhas anonCleanupthat calls the globalsyncStatewhich disposes the entire Solid root thatAis rendered in, thenAwill error in thecleanNodefunction.I believe that this change should solve this problem, but I would love input on whether this change is reasonable at all, or whether it may have side effects that I haven't considered.
Thank you!
How did you test this change?
Would love advice on where you think it'd be best to add a test for this — didn't do it yet, because would first love input on whether this change makes sense.