From a69efec3f03b70e5279c069aa80d3bc91c8a6e83 Mon Sep 17 00:00:00 2001 From: Johannes Gezachew Date: Sat, 12 Sep 2026 17:38:47 +0300 Subject: [PATCH] docs: correct createContext guidance for server rendering The createContext JSDoc told readers to reach for a module-scope signal or store for app-wide state. With ssr: true a module is evaluated once per process, so that state is shared by every request: a store derived from a server function leaks one user's data into another's render, and a module-scope signal has no owner to dispose it. The 2.0 docs say the opposite, and the reference page is generated from this JSDoc, so the site contradicted itself. Also fix two smaller items in the same examples: - The createContext and useContext @example blocks render , whose stub returns nothing, so the examples fail tsc as written. - The handleServerFunctionRequest @example imported from "@solidjs/web/server-functions", which resolves to the client entry under the browser condition; the function is exported from "@solidjs/web/server-functions/server". --- packages/solid/src/client/core.ts | 10 +++++++--- packages/web/server-functions/src/server.ts | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/solid/src/client/core.ts b/packages/solid/src/client/core.ts index 5e1f252bb..c523b99d8 100644 --- a/packages/solid/src/client/core.ts +++ b/packages/solid/src/client/core.ts @@ -61,9 +61,11 @@ export interface Context extends ContextProviderComponent { * static fallback (theme, locale, frozen config). Outside any Provider, * `useContext` returns `defaultValue`. * - * If you want truly app-wide state, **don't use Context** — a module-scope - * signal/store *is* a global. Context is for scoping state to a subtree; - * that's why a Provider is required. + * Context is for state that belongs to a subtree, which includes app-wide + * state in an app that renders on the server: a value created inside a + * component is created once per request, and the Provider owns and disposes + * it. Module scope is shared by every request in the same process, so reserve + * it for constants. * * @param defaultValue optional default; only meaningful for primitive * fallbacks. Omit for any context carrying reactive state. @@ -87,6 +89,7 @@ export interface Context extends ContextProviderComponent { * function TodoList() { * const [todos, { addTodo }] = useContext(TodosContext); // typed as TodosCtx * // ... + * return null; * } * ``` * @@ -142,6 +145,7 @@ export function createContext(defaultValue?: T, options?: EffectOptions): Con * function TodoList() { * const [todos, { addTodo }] = useContext(TodosContext); // throws if no Provider * // ... + * return null; * } * ``` * diff --git a/packages/web/server-functions/src/server.ts b/packages/web/server-functions/src/server.ts index 13f7bb8fe..3ded0a013 100644 --- a/packages/web/server-functions/src/server.ts +++ b/packages/web/server-functions/src/server.ts @@ -3236,7 +3236,7 @@ function nativePromise(value) { * * @example * ```ts - * import { handleServerFunctionRequest } from "@solidjs/web/server-functions"; + * import { handleServerFunctionRequest } from "@solidjs/web/server-functions/server"; * import "virtual:solid-server-function-manifest"; * * // in the server's request handling: