[2.0] `createContext(undefined)` throws ContextNotFoundError, even when a provider passes `undefined`
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 56/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript, typescript
調査の方向性
Start in packages/signals/src/core/context.ts and read getContext alongside the reported examples. Reproduce the cases for an explicit undefined default and provider value, then check how context errors affect computations. Done means the chosen behavior matches the expected cases and the error or docs explain the undefined behavior; the issue does not name a test file.
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
getContext (packages/signals/src/core/context.ts) treats undefined as "not found":
let value = owner._context[context.id];
if (value === undefined) value = context.defaultValue;
if (value === undefined) throw new ContextNotFoundError();
So createContext<T | undefined>(undefined), the most common optional-context idiom in React and Solid 1 (where useContext returned undefined), throws when read outside a provider. It also throws when a provider explicitly passes undefined. Inside a computation, the throw halts reactivity for the whole app (#4178).
The message, "Context must either be created with a default value or a value must be provided before accessing it", sounds wrong when the caller did pass a default.
Your Example Website or App
Minimal repro inline below (signals-only).
Steps to Reproduce the Bug or Issue
import { createContext, getContext, setContext, createRoot, createSignal, createRenderEffect, flush } from "@solidjs/signals";
const Opt = createContext<string | undefined>(undefined);
const OptNull = createContext<string | null>(null);
createRoot(() => getContext(Opt)); // throws ContextNotFoundError
createRoot(() => { setContext(Opt, "x"); getContext(Opt); }); // "x"
createRoot(() => { setContext(Opt, undefined); getContext(Opt); }); // throws ContextNotFoundError
createRoot(() => getContext(OptNull)); // null
// Inside a computation:
const [show, setShow] = createSignal(false);
const [b, setB] = createSignal(0);
createRoot(() => createRenderEffect(b, v => console.log("b", v)));
createRoot(() => createRenderEffect(() => (show() ? getContext(Opt) : null), () => {}));
flush();
setShow(true); flush(); // StatusError (ContextNotFoundError) + [REACTIVITY_HALTED]
setB(1); flush(); // "b 1" never logs
Expected behavior
- Distinguish "no default argument" from an explicit
undefineddefault (arguments.lengthor a sentinel), and throw only for the former. - Treat a provider's explicit
value={undefined}as a provided value. - If that's not wanted, at minimum say in the error message and the docs/cheatsheet that
undefinedcounts as missing, and thatnullis the way to make a context optional.
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 verifying examples for the From React docs additions (solidjs/solid-docs#1664). It's also a silent migration break from 1.x, where useContext returned undefined.
- 主要言語
- TypeScript
- スター
- 36.2k
- フォーク
- 1.1k
- 平均マージ
- 11時間 17分
- マージ済み PR(30日)
- 371
環境構築
- 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 が 5 日前に担当しました。 オープン1.x
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
solidjs/solid#4182 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
`createRoot`'s dispose function keeps `fn` alive, so `<For>`/`<Index>` rows retain removed list items対応中かも @boombang が 7 日前に担当しました。 オープン1.x
難易度 4/5 1〜2日 初心者へのやさしさ 45/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
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 76/100
logto-io/logto#9837 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
難易度 1/5 1時間未満 初心者へのやさしさ 76/100
lingdojo/kana-dojo#32964 · コメント 1 件 · リアクション 5 件 ·
メンテナーはふだん 1 日以内に返信
-
Documentation status: needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
mastra-ai/mastra#28194 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
priority-low refactor-3
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 3 日以内に返信