|
24 | 24 | * entries mark them `@internal` and strip them from their declarations. |
25 | 25 | * The boundary primitives behind `Errored`, `Loading`, and `Reveal` are |
26 | 26 | * read back the same way (real on both entries), for renderers that |
27 | | - * build boundaries without the components. |
| 27 | + * build boundaries without the components, and so are `sharedConfig` |
| 28 | + * (the hydration/SSR coordination object) and the `$DEVCOMP` brand. |
28 | 29 | */ |
29 | 30 | import * as core from "solid-js"; |
30 | 31 | import type { Accessor, RevealOrder, ServerErrorHook, ServerErrorSite } from "solid-js"; |
| 32 | +import type { HydrationContext } from "./server/shared.js"; |
31 | 33 |
|
32 | 34 | export { |
33 | 35 | mergeSources, |
@@ -139,3 +141,71 @@ export const createRevealOrder: <T>( |
139 | 141 | fn: () => T, |
140 | 142 | options?: { order?: () => RevealOrder; collapsed?: () => boolean } |
141 | 143 | ) => T = core.createRevealOrder; |
| 144 | + |
| 145 | +/** |
| 146 | + * The shape `sharedConfig` has on either entry. The two objects share the |
| 147 | + * name, not the members: the client's carries hydration state, populated by |
| 148 | + * `enableHydration()` and the DOM runtime's `hydrate()`; the server's carries |
| 149 | + * the render's `context` and the id allocator. Every member is therefore |
| 150 | + * optional — a member is present only on the tier (and, for some, only in |
| 151 | + * the phase) that sets it. |
| 152 | + */ |
| 153 | +interface SharedConfig { |
| 154 | + /** |
| 155 | + * Both: the next hydration key under the current owner, `undefined` under |
| 156 | + * `NoHydration`. Server: always present. Client: assigned by |
| 157 | + * `enableHydration()`, read only behind a `hydrating` check. |
| 158 | + */ |
| 159 | + getNextContextId?: () => string | undefined; |
| 160 | + /** |
| 161 | + * Both, dev builds only: the id `getNextContextId()` would hand out next, |
| 162 | + * read without consuming it (`undefined` outside an id-carrying tree). |
| 163 | + * Callers gate on `_SOLID_DEV_`. |
| 164 | + */ |
| 165 | + devPeekNextContextId?: () => string | undefined; |
| 166 | + /** Server: the hydration context of the render in progress, absent outside one. */ |
| 167 | + context?: HydrationContext; |
| 168 | + /** Client: whether a hydration pass is claiming server-rendered DOM right now. */ |
| 169 | + hydrating?: boolean; |
| 170 | + /** Client: whether hydration has completed. */ |
| 171 | + done?: boolean; |
| 172 | + resources?: { [key: string]: any }; |
| 173 | + /** Client: reads a serialized value by id from the hydration payload. */ |
| 174 | + load?: (id: string) => Promise<any> | any; |
| 175 | + /** Client: whether the hydration payload carries `id`. */ |
| 176 | + has?: (id: string) => boolean; |
| 177 | + /** Client: collects the server-rendered nodes under the hydration root `key` into `registry`. */ |
| 178 | + gather?: (key: string) => void; |
| 179 | + /** Client: the server-rendered nodes of the active root, by hydration key. */ |
| 180 | + registry?: Map<string, object>; |
| 181 | + /** |
| 182 | + * Client: the registry/gather pair each streamed boundary registered |
| 183 | + * under, keyed by boundary id, so a late resume claims against its own root. |
| 184 | + */ |
| 185 | + boundaryScopes?: Map<string, { registry?: Map<string, object>; gather?: (key: string) => void }>; |
| 186 | + captureBoundaryScope?: (id: string) => void; |
| 187 | + cleanupFragment?: (id: string) => void; |
| 188 | + loadModuleAssets?: (mapping: Record<string, string>) => Promise<void> | undefined; |
| 189 | + completed?: WeakSet<object> | null; |
| 190 | + events?: any[] | null; |
| 191 | + verifyHydration?: () => void; |
| 192 | + /** Client: whether a hydration pass is still claiming — absent means "not hydrating". */ |
| 193 | + isHydrationInProgress?: () => boolean; |
| 194 | + /** Client: runs `callback` once all hydration completes — absent means it already has. */ |
| 195 | + onHydrationEnd?: (callback: () => void) => void; |
| 196 | + /** Client: whether a render under the current owner is part of the claim in progress — absent means "claiming". */ |
| 197 | + isClaiming?: () => boolean; |
| 198 | +} |
| 199 | + |
| 200 | +/** |
| 201 | + * The hydration/SSR coordination object the core shares with its renderers |
| 202 | + * — the client entry's or the server entry's, whichever the app runs. |
| 203 | + */ |
| 204 | +export const sharedConfig: SharedConfig = core.sharedConfig; |
| 205 | + |
| 206 | +/** |
| 207 | + * Dev builds: the brand the component wrapper sets on every component it |
| 208 | + * runs (`Comp[$DEVCOMP] === true`), read by the refresh runtime and |
| 209 | + * devtools. Other builds: a symbol nothing sets. |
| 210 | + */ |
| 211 | +export const $DEVCOMP: symbol = core.$DEVCOMP; |
0 commit comments