[2.0 rc.9] Production build runs component onCleanup callbacks parent-before-child (dev, observe and 1.x run child-first)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 55/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- javascript, typescript
- 領域
- frontend
調査の方向性
Start with runDisposal in packages/signals/src/core/owner.ts and the reverse-order cleanup test in packages/signals/tests/onCleanup.test.ts. Compare that behavior with production createComponent in packages/solid/src/client/component.ts and the development path in packages/solid/src/client/core.ts. Done means nested component cleanups run child-before-parent in production and the relevant tests pass.
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
In the production build, onCleanup callbacks registered in component bodies run parent before child. The development and observe builds run child before parent, and so did every build of 1.x. The change only shows up in production, so nothing catches it during development.
import { createRoot, createComponent, onCleanup, DEV } from "solid-js";
const log = [];
const Grandchild = () => { onCleanup(() => log.push("grandchild")); return null; };
const Child = () => { onCleanup(() => log.push("child")); return createComponent(Grandchild, {}); };
const Parent = () => { onCleanup(() => log.push("parent")); return createComponent(Child, {}); };
const dispose = createRoot(d => { createComponent(Parent, {}); return d; });
dispose();
console.log((DEV ? "dev " : "prod") + " build:", JSON.stringify(log));
| run | output |
|---|---|
node --conditions=browser repro.mjs (2.0.0-rc.9 production) |
["parent","child","grandchild"] |
node --conditions=browser --conditions=development repro.mjs |
["grandchild","child","parent"] |
same two runs against the server builds (no browser condition) |
same split |
| solid-js 1.9.15, production build | ["grandchild","child","parent"] |
| solid-js 1.9.15, development build | ["grandchild","child","parent"] |
The consequence in an app is a parent that tears down a resource its children are still attached to:
const Series = (p) => { onCleanup(() => p.chart.removeSeries()); return <i>series</i>; };
const Chart = () => {
const chart = makeChart(); // any library object: chart, map, editor, socket
onCleanup(() => chart.destroy());
return <section><Series chart={chart} /></section>;
};
<Show when={open()} fallback={<u>closed</u>}><Chart /></Show>
Development: setOpen(false) logs removeSeries, then destroy. Production: destroy runs first, removeSeries() throws on the destroyed chart, and after that throw nothing on the page updates again — the <Show> never switches to closed, and unrelated buttons stop working. The same page in the development build keeps working.
Your Example Website or App
The script above runs against the built packages with plain node; the JSX example is what it looks like in a page.
Steps to Reproduce the Bug or Issue
- Save the first snippet as
repro.mjsnext to a built checkout (or any project with[email protected]installed). - Run
node --conditions=browser repro.mjsandnode --conditions=browser --conditions=development repro.mjs. - Compare the printed order.
For the page version, mount the Chart/Series tree under a <Show> in a production build, toggle the <Show> off, and click anything else on the page.
Expected behavior
Children clean up before their parents in every build, as they did in 1.x, and as the development build still does. The signals core tests this contract for nested owners (packages/signals/tests/onCleanup.test.ts, "should clean up in reverse order").
Platform
- solid-js 2.0.0-rc.9 (
next@ 37fd1e67), production vs development builds - Node 24.21, macOS arm64; solid-js 1.9.15 used for the comparison rows
Additional context
Two things combine:
- The production
createComponentisuntrack(() => Comp(props))with no owner of its own (packages/solid/src/client/component.ts:85), while the development and observe builds run every component insidecreateRoot(…, { transparent: true })(observedComponent,packages/solid/src/client/core.ts:209-241). So in production a parent's and its children's cleanups all land on the same enclosing computation's disposal list, in registration order: parent first, because the parent's body runs before it creates the child. runDisposalwalks that list forwards (packages/signals/src/core/owner.ts:168-183).
1.x also had no owner per component in production (the open #1561 is about that dev/prod split), but its cleanNode ran a node's cleanups in reverse (for (i = node.cleanups.length - 1; i >= 0; i--) in solid-js 1.9.15), so the order came out child-first anyway. 2.0 replaced that with a forward walk, which is what turns the old inconsistency into wrong behaviour.
The smallest change that restores the 1.x order is to walk _disposal in reverse in runDisposal. Giving production components an owner, as the development build does, would also fix it and would make getOwner() / isDisposed(owner) in a component body mean the same thing in both builds (today the production owner is the enclosing computation, shared by sibling components, so the bail-out pattern in isDisposed's own docstring never fires after a component unmounts).
A second effect worth knowing about while fixing this: once a cleanup throws during a flush, schedule() (packages/signals/src/core/scheduler.ts:404-412) is left latched, so no further microtask flush is ever queued and the page is dead until something calls flush() explicitly. That is why the page example stops responding rather than just logging an error.
- 主要言語
- TypeScript
- スター
- 36.1k
- フォーク
- 1.1k
- 平均マージ
- 10時間 41分
- マージ済み PR(30日)
- 363
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
solidjs/solid のほかの issue
-
難易度 3/5 半日 初心者へのやさしさ 55/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 半日 初心者へのやさしさ 45/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
signals: a landing reveals a held write its stale reader re-derives onto a new flight (U-5, D-9)オープン
難易度 5/5 1週間以上 初心者へのやさしさ 12/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
dsh-market/dsh-market#877 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
stellar/stellar-dev-skill#151 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
area:arcade game ready-for-agent
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
fderuiter/deruiter.dev#2281 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
scope: data grid type: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 2 日以内に返信