Conversation
|
|
I think it does. The only challenge is concurrency. That being said I don't think it changes the desire for this. Just it complicates things a bit. |
|
Was this resolved in a different way? The linked playground no longer throws an error. |
|
Here is a snippet where a similar error occurs: import { render } from "solid-js/web";
import { createMemo } from "solid-js";
import { MetaProvider, Title } from "@solidjs/meta";
import { Route, Router, useNavigate, useParams } from "@solidjs/router";
function RepoPage() {
const navigate = useNavigate();
const params = useParams<{ id?: string }>();
const title = createMemo(() => params.id ?? "");
return (
<div>
<Title>{title()}</Title>
<button onClick={() => navigate("/")}>Back</button>
</div>
);
}
function HomePage() {
const navigate = useNavigate();
return <button onClick={() => navigate("/x")}>Go</button>;
}
function App() {
return (
<MetaProvider>
<Router>
<Route path="/:id" component={RepoPage} />
<Route path="/" component={HomePage} />
</Router>
</MetaProvider>
);
}
render(() => <App />, document.getElementById("root")!);Versions: The error is thrown when the Back button is clicked. The app crashes (freezes), and the following gets logged: Crash logAn important detail is that removing The fix proposed in this PR does indeed stop the error from happening. That said, the following change (made on top of signal.ts in main) also fixes it. Alternative fix
From what I can tell, the issue is that The changes proposed above avoids that by snapshotting the child list into a local variable and detaching it from the node before recursing, so the recursive cleanup no longer depends on a field that may be mutated during re-entry. UPDATEThe scenario I outlined above was apparently being caused by Even though the proposed fix is small and non intrusive, if it is true that “Solid’s cleanup code assumes cleanup functions don’t perform reactive reads that can re-run computations,” then I’m not sure it makes sense to guard against what may ultimately be a misuse case. The fix may even introduce silent leaks, I didn't end up testing against that, so I don't know -- would need an expert opinion on this. |

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.