[2.0] `createContext(undefined)` throws ContextNotFoundError, even when a provider passes `undefined`
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 56/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript, typescript
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 36.2k
- Fork
- 1.1k
- Merge trung bình
- 11 giờ 17 phút
- Pull request đã merge (30 ngày)
- 371
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của solidjs/solid
-
`lazy()`: remounting an already-loaded component renders empty (or the Suspense fallback) since 1.9.14Có thể đã có người làm @itisrmk đã nhận 5 ngày trước. Đang mở1.x
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
solidjs/solid#4182 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
-
`createRoot`'s dispose function keeps `fn` alive, so `<For>`/`<Index>` rows retain removed list itemsCó thể đã có người làm @boombang đã nhận 7 ngày trước. Đang mở1.x
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 45/100
Maintainer thường phản hồi trong vòng 1 ngày
-
signals: a landing reveals a held write its stale reader re-derives onto a new flight (U-5, D-9)Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 12/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của solidjs/solid
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
cursor/community-plugins#465 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
vetro-protocol/vetro-monorepo#978 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ai-generated bug category:security effort:s priority:p3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
LanternOps/breeze#9697 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
maniator/verticopolis#1303 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
components-web-app/docs#297 ·