`createRoot`'s dispose function keeps `fn` alive, so `<For>`/`<Index>` rows retain removed list items
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript, typescript
- 領域
- frontend, performance
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- TypeScript
- スター
- 36.2k
- フォーク
- 1.1k
- 平均マージ
- 10時間 34分
- マージ済み PR(30日)
- 364
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
solidjs/solid のほかの issue
-
`lazy()`: remounting an already-loaded component renders empty (or the Suspense fallback) since 1.9.14対応中かも @itisrmk が 6 日前に担当しました。 オープン1.x
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
[2.0] Event handlers fired synchronously from an effect (focus(), showModal()) inherit the effect's strict-read window対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 44/100
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
Per-scope takeover for live nodes whose server value is still streaming (D8 follow-up to #3817)オープン
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
Nimblesite/SharpLsp#468 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
Bundled uv is never updated and trusts the compromised eMudhra certificates対応中かも @FabienDanieau が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
bg_wait's blocking mode (stopOnAttention: false) is under-documented and effectively undiscoverableオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
nicobailon/pi-subagents#3019 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
db-ux-design-system/core-web#8613 ·
メンテナーはふだん 1 日以内に返信