[2.0] The MIGRATION.md replacement for `from()` keeps the upstream subscription after dispose; add a subscription helper
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- typescript
調査の方向性
Start with documentation/solid-2.0/MIGRATION.md and the consumeIterator behavior described in the issue; the minimal reproduction shows how disposal leaves the upstream subscription open. Compare the migration guidance with the From React page additions referenced in the payload. Done means the docs explain safe teardown and an official reusable subscription approach is available or the issue’s API proposal has a clear resolution.
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
documentation/solid-2.0/MIGRATION.md ("from / observable → async iterators / effects") recommends:
const value = createMemo(async function* () {
for await (const val of observable$) yield val;
});
After the owner is disposed, the upstream iterator's return() is not called. It runs only when the upstream produces another value, which may never happen. The cause is that the generator is suspended at an await (inside for await), so its return() is queued behind the pending step. Solid's side is correct: consumeIterator calls return() on dispose and on supersede.
Your Example Website or App
Minimal repro inline below (signals-only).
Steps to Reproduce the Bug or Issue
import { createMemo, createRoot, createRenderEffect, flush } from "@solidjs/signals";
let push: (v: number) => void;
let closed = 0;
const observable$: AsyncIterable<number> = {
[Symbol.asyncIterator]: () => ({
next: () => new Promise(r => (push = v => r({ value: v, done: false }))),
return: async () => { closed++; return { value: undefined, done: true }; }
})
};
const dispose = createRoot(d => {
const value = createMemo(async function* () { for await (const v of observable$) yield v; }, { loadingValue: 0 });
createRenderEffect(value, v => console.log("value", v));
return d;
});
flush(); push!(1); /* await a few microtasks */ flush(); // logs 0, 1
dispose(); /* await 50 microtasks */
console.log(closed); // 0: upstream still subscribed
push!(2); /* await */
console.log(closed); // 1: closes only after the next upstream value
By contrast, a hand-written iterator whose return() unsubscribes synchronously behaves well. I tested:
isPendingstaysfalsewhile the memo waits for the next value;loadingValuecovers the first read;return()unsubscribes immediately on dispose;- bursts coalesce into one update with a dirty flag.
It's about 20 lines and easy to get wrong:
function fromSubscription<T>(subscribe: (cb: () => void) => () => void, getSnapshot: () => T): AsyncIterable<T> {
return {
[Symbol.asyncIterator]() {
let dirty = true, done = false;
let wake: ((r: IteratorResult<T>) => void) | undefined;
const unsubscribe = subscribe(() => {
dirty = true;
if (wake) { const w = wake; wake = undefined; dirty = false; w({ value: getSnapshot(), done: false }); }
});
return {
next: () => {
if (done) return Promise.resolve({ value: undefined, done: true });
if (dirty) { dirty = false; return Promise.resolve({ value: getSnapshot(), done: false }); }
return new Promise(r => (wake = r));
},
return: () => {
done = true; unsubscribe();
wake?.({ value: undefined, done: true }); wake = undefined;
return Promise.resolve({ value: undefined, done: true });
}
};
}
};
}
Expected behavior
- Docs: fix the MIGRATION.md snippet so disposal actually unsubscribes, and document (or flag in dev) that
async function*+awaitdelays teardown until the next upstream value. - API: provide a helper equivalent to React's
useSyncExternalStore/ Solid 1'sfrom:
MIGRATION.md says this is expected to "move into @solid-primitives". Given how central external stores are to incremental migrations (keeping existing domain stores and putting Solid on top), it may be worth a minimal version in core. Either way, a correct, reusable implementation should exist somewhere official.const online = createMemo(() => fromSubscription(subscribe, () => navigator.onLine), { loadingValue: true });
Screenshots or Videos
No response
Platform
- OS: macOS (Darwin 25.5)
- Browser: n/a (reproduced in Node v24.18.0 with vitest, importing source)
- Version: solid
next@ b0ad1df50 (2026-10-20, after 2.0.0-rc.16)
Additional context
This came up while documenting useSyncExternalStore for the From React page (solidjs/solid-docs#1664). The From React additions describe the hand-written iterator and warn against async function* for this.
- 主要言語
- TypeScript
- スター
- 36.1k
- フォーク
- 1.1k
- 平均マージ
- 11時間 42分
- マージ済み PR(30日)
- 350
環境構築
- 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 が 4 日前に担当しました。 オープン1.x
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 1 日以内に返信
-
[2.0] Effects re-run (and run cleanup) when the compute returns an equal value; there's no `equals` option対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 54/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 56/100
メンテナーはふだん 1 日以内に返信
-
[compiler] A valueless `prop:` attribute is dropped silently by both compilers対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
ready-for-agent
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
xavxyz/bei-shan-lin-shui#57 ·
メンテナーはふだん 1 日以内に返信
-
[BUG] rag: sentence content can cross the reported sentence boundaries対応中かも @LJK-ikun が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
bug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
README: the Resource URI Schemas example's file://documents/* pattern only matches that literal URIオープン
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
platformatic/mcp#361 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
siyuan-note/siyuan#20799 · コメント 7 件 ·
メンテナーはふだん 1 日以内に返信