`createRoot`'s dispose function keeps `fn` alive, so `<For>`/`<Index>` rows retain removed list items
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, typescript
- Ambito
- frontend, performance
Direzione di ricerca
Start with createRoot and the updateFn line that builds the dispose closure, then trace how mapArray and indexArray store each row's disposer in disposers. Run the repro script with node --expose-gc --conditions=browser repro.mjs. Done means both lines print false, and the existing tests for createRoot and the array helpers still pass.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
createRoot creates the dispose function it passes to fn inside its own scope:
updateFn = unowned ? ... : () => fn(() => untrack(() => cleanNode(root)));
That scope also holds fn, because updateFn closes over it. So anything that keeps the dispose function also keeps fn, and everything fn closes over.
mapArray and indexArray keep every row's dispose function in disposers. Every row's fn is mapper, and mapper closes over newItems, the list that was current when the row was created. So a mounted row keeps that whole list reachable, including items that were removed from the list later.
We found this in production. A long-lived <For> row kept a list it was created from, and with it a replaced document of a few hundred MB.
Your Example Website or App
Standalone script below (Node 22, solid-js 1.9.17, client build).
Steps to Reproduce the Bug or Issue
// npm i [email protected]
// node --expose-gc --conditions=browser repro.mjs
import { createRoot, createSignal, createMemo, mapArray, indexArray } from "solid-js";
const collect = async () => {
// WeakRef targets stay alive until the current job ends.
await new Promise(r => setTimeout(r, 0));
globalThis.gc();
};
// A row created from [kept, removed] stays mounted after the list becomes [kept].
async function check(name, map) {
const kept = { name: "kept" };
let removed, setList;
const dispose = createRoot(dispose => {
const [list, set] = createSignal(
(() => {
const item = { name: "removed" };
removed = new WeakRef(item);
return [kept, item];
})()
);
setList = set;
createMemo(map(list))();
return dispose;
});
setList([kept]);
await collect();
console.log(`${name}: removed item still reachable:`, removed.deref() !== undefined);
dispose();
}
await check("mapArray (<For>)", list => mapArray(list, item => item.name));
await check("indexArray (<Index>)", list => indexArray(list, item => item().name));
Output:
mapArray (<For>): removed item still reachable: true
indexArray (<Index>): removed item still reachable: true
The dev build (dist/dev.js) gives the same output, and so does Bun (JavaScriptCore) with Bun.gc(true).
Expected behavior
Once the row for removed is disposed, nothing should keep removed reachable, so both lines should print false. They do once the dispose function is created outside createRoot's scope, in both V8 and JavaScriptCore.
Platform
- solid-js: 1.9.17 (
main) - Node 22.23 (V8), Bun 1.4.2 (JavaScriptCore)
Additional context
I haven't checked next (2.0) yet. The fix for 1.x is in the PR linked below.
- Lingua principale
- TypeScript
- Stelle
- 36.1k
- Fork
- 1.1k
- Merge medio
- 11h 42m
- PR unite (30g)
- 350
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di solidjs/solid
-
`lazy()`: remounting an already-loaded component renders empty (or the Suspense fallback) since 1.9.14Forse già presa @itisrmk l’ha presa 3 giorni fa. Aperta1.x
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
I maintainer di solito rispondono entro 1 giorno
-
[2.0] Effects re-run (and run cleanup) when the compute returns an equal value; there's no `equals` optionForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 54/100
I maintainer di solito rispondono entro 1 giorno
-
[2.0] The MIGRATION.md replacement for `from()` keeps the upstream subscription after dispose; add a subscription helperForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 56/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di solidjs/solid
Issue simili
-
Edit: Tele Posadas HDApertacheck:passed streams:edit
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
area:mcp bug has repro platform:vscode regression
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
anthropics/claude-code#103970 ·
I maintainer di solito rispondono entro 1 giorno
-
skillopt: success-reflect prompt omits the edit schema, so every success-only edit is droppedAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Workspace secrets/constants containing "$" are corrupted when resolved in data source optionsApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
sdk-typescript: unquoted COPY globs in shell form are silently dropped from the image build contextApertabug javascript
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno