@solidjs/web 2.0.0-rc.14 → 2.0.0-rc.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1595,20 +1595,28 @@ function createServerReference({
1595
1595
  const scope = run => provideEvent(evt, run);
1596
1596
  const wrap = resolveWrapInvocation(config.wrapInvocation);
1597
1597
  const hook = requestErrorHook(ogEvt);
1598
- let result = provideEventOnce(provideEvent, evt, () => {
1599
- const run = () => fn.apply(thisArg, args);
1600
- return observeInvocation({
1601
- id,
1602
- direct: true,
1603
- event: evt,
1604
- args
1605
- }, () => reportDirectFailure(() => wrap ? wrap(run, {
1606
- id,
1607
- args,
1608
- event: evt,
1609
- direct: true
1610
- }) : run(), id, hook));
1611
- });
1598
+ let result;
1599
+ try {
1600
+ result = provideEventOnce(provideEvent, evt, () => {
1601
+ const run = () => fn.apply(thisArg, args);
1602
+ return observeInvocation({
1603
+ id,
1604
+ direct: true,
1605
+ event: evt,
1606
+ args
1607
+ }, () => reportDirectFailure(() => wrap ? wrap(run, {
1608
+ id,
1609
+ args,
1610
+ event: evt,
1611
+ direct: true
1612
+ }) : run(), id, hook));
1613
+ });
1614
+ } catch (error) {
1615
+ throw directEnvelopeValue(error, evt);
1616
+ }
1617
+ result = result && typeof result.then === "function" ? result.then(value => directEnvelopeValue(value, evt), error => {
1618
+ throw directEnvelopeValue(error, evt);
1619
+ }) : directEnvelopeValue(result, evt);
1612
1620
  result = scopeDeferredResult(result, scope);
1613
1621
  const transform = config.transformDirectResult;
1614
1622
  if (transform && result && typeof result.then === "function") {
@@ -2492,7 +2500,7 @@ function encodeLiveResult(value, headers, status, codec, request, scope) {
2492
2500
  function encodeResult(value, headers, status, codec, signal, scope) {
2493
2501
  if (NULL_BODY_STATUSES.has(status)) {
2494
2502
  if (value === undefined || value === null) {
2495
- headers.set(BODY_FORMAT_HEADER, BodyFormat.Void);
2503
+ if (status !== 304) headers.set(BODY_FORMAT_HEADER, BodyFormat.Void);
2496
2504
  return new Response(null, {
2497
2505
  status,
2498
2506
  headers
@@ -2579,6 +2587,7 @@ function currentEvent() {
2579
2587
  }
2580
2588
  function reportDirectFailure(run, id, hook) {
2581
2589
  const report = error => {
2590
+ if (error instanceof Response || isResponseEnvelope(error)) throw error;
2582
2591
  reportServerError(error, {
2583
2592
  kind: "server-function",
2584
2593
  handling: "thrown",
@@ -2595,6 +2604,20 @@ function reportDirectFailure(run, id, hook) {
2595
2604
  }
2596
2605
  return result && typeof result.then === "function" ? result.then(undefined, report) : result;
2597
2606
  }
2607
+ function directEnvelopeValue(result, event) {
2608
+ if (!isResponseEnvelope(result)) return result;
2609
+ const {
2610
+ response,
2611
+ value
2612
+ } = result;
2613
+ const stub = event.response;
2614
+ if (response && stub && stub.headers && response.headers.getSetCookie) {
2615
+ for (const cookie of response.headers.getSetCookie()) {
2616
+ stub.headers.append("Set-Cookie", cookie);
2617
+ }
2618
+ }
2619
+ return value;
2620
+ }
2598
2621
  function sanitizeServerError(value) {
2599
2622
  if (DEV) return value;
2600
2623
  if (isSafeError(value)) return value;
@@ -2843,8 +2866,14 @@ async function handleServerFunctionRequest(request, options = {}) {
2843
2866
  });
2844
2867
  return finish(protectsRequest ? withCSRFVary(response) : response);
2845
2868
  }
2869
+ const commitResponse = raw => {
2870
+ if ((method === "GET" || method === "HEAD") && (sharedCacheMayStore(departingHeader(raw, event, "Cache-Control")) || cdnMayStore(departingHeader(raw, event, "CDN-Cache-Control")))) {
2871
+ withholdTrace(event);
2872
+ }
2873
+ return commitEventResponse(raw, event);
2874
+ };
2846
2875
  const refuseCommitted = raw => {
2847
- const response = commitEventResponse(raw, event);
2876
+ const response = commitResponse(raw);
2848
2877
  return finish(protectsRequest ? withCSRFVary(response) : response);
2849
2878
  };
2850
2879
  const provide = options.provideEvent || provideEvent;
@@ -3062,9 +3091,54 @@ async function handleServerFunctionRequest(request, options = {}) {
3062
3091
  return respondThrown(x);
3063
3092
  }
3064
3093
  };
3065
- const response = commitEventResponse(enforceComposedHeaderInvariants(ownResponse(await dispatch())), event);
3094
+ const response = commitResponse(enforceComposedHeaderInvariants(ownResponse(await dispatch())));
3066
3095
  return finish(protectsRequest ? withCSRFVary(response) : response);
3067
3096
  }
3097
+ function departingHeader(response, event, name) {
3098
+ const own = response.headers.get(name);
3099
+ if (own !== null) return own;
3100
+ const stub = event.response;
3101
+ return stub && stub.headers && !stub.committed ? stub.headers.get(name) : null;
3102
+ }
3103
+ function cdnMayStore(cdnCacheControl) {
3104
+ return cdnCacheControl !== null && !forbidsStoring(cdnCacheControl);
3105
+ }
3106
+ function sharedCacheMayStore(cacheControl) {
3107
+ let shared = false;
3108
+ return !!cacheControl && !eachDirective(cacheControl, name => {
3109
+ if (name === "public" || name === "s-maxage") shared = true;
3110
+ }) && shared;
3111
+ }
3112
+ function forbidsStoring(value) {
3113
+ return eachDirective(value, () => {});
3114
+ }
3115
+ function eachDirective(value, visit) {
3116
+ let start = 0;
3117
+ let quoted = false;
3118
+ for (let i = 0; i <= value.length; i++) {
3119
+ const c = value[i];
3120
+ if (quoted) {
3121
+ if (c === "\\") i++;else if (c === '"') quoted = false;
3122
+ continue;
3123
+ }
3124
+ if (c === '"') {
3125
+ quoted = true;
3126
+ continue;
3127
+ }
3128
+ if (c !== "," && i < value.length) continue;
3129
+ const directive = value.slice(start, i);
3130
+ start = i + 1;
3131
+ const eq = directive.indexOf("=");
3132
+ const name = (eq === -1 ? directive : directive.slice(0, eq)).trim().toLowerCase();
3133
+ if (name === "no-store" || name === "private" && eq === -1) return true;
3134
+ visit(name);
3135
+ }
3136
+ return false;
3137
+ }
3138
+ function withholdTrace(event) {
3139
+ if (event.response && event.response.committed) return;
3140
+ traceForEvent(event).emit = false;
3141
+ }
3068
3142
  function ownResponse(response) {
3069
3143
  try {
3070
3144
  return new Response(response.body, response);
package/types/client.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { getOwner, createComponent, untrack, merge as mergeProps } from "solid-js";
2
- import type { ClientErrorHook } from "solid-js";
2
+ import type { ClientErrorHook, Owner } from "solid-js";
3
3
  import { effect, memo } from "./render.js";
4
4
  import { JSX } from "./jsx.js";
5
- import type { RequestEventLocals, HydrationWriter, HydrationValue } from "./server.js";
5
+ import type { RequestEventLocals, HydrationWriter, HydrationValue, LinkClaimHandler } from "./server.js";
6
6
  import type { TraceContext } from "./trace.js";
7
7
  type MountableElement = Element | Document | ShadowRoot | DocumentFragment | Node;
8
8
  /**
@@ -74,7 +74,7 @@ export interface ResponseStub {
74
74
  * `locals`, whichever entry typed the event.
75
75
  */
76
76
  export { RequestEventLocals } from "./server.js";
77
- export type { HydrationWriter, HydrationValue } from "./server.js";
77
+ export type { HydrationWriter, HydrationValue, LinkClaimHandler } from "./server.js";
78
78
  export interface RequestEvent {
79
79
  request: Request;
80
80
  locals: RequestEventLocals;
@@ -85,14 +85,18 @@ export type { TraceContext, TraceProvider } from "./trace.js";
85
85
  export type { ServerFunction, ServerFunctionMetadata, ServerFunctionRPC } from "./server-functions/shared.js";
86
86
  export declare const waitAsset: (promise: Promise<unknown>) => void;
87
87
  export { DOMWithState, ChildProperties, DOMElements, SVGElements, MathMLElements, VoidElements, RawTextElements, Namespaces, DelegatedEvents } from "./constants.js";
88
+ type CSPNonce = string | {
89
+ script: string | false;
90
+ style: string | false;
91
+ };
88
92
  /** Client stub — hydration bootstrap is a server-only emit. */
89
93
  export declare function generateHydrationScript(_options?: {
90
94
  eventNames?: string[];
91
- nonce?: string;
95
+ nonce?: CSPNonce;
92
96
  }): string;
93
97
  /** Client stub — valid JSX component, renders nothing. */
94
98
  export declare function HydrationScript(_props?: {
95
- nonce?: string;
99
+ nonce?: CSPNonce;
96
100
  eventNames?: string[];
97
101
  }): null;
98
102
  export { effect, memo, untrack, getOwner, createComponent };
@@ -118,6 +122,24 @@ export declare const getHydrationWriter: () => HydrationWriter | undefined;
118
122
  * `globalThis._$HY = { r: { "sq:key": value } }`.
119
123
  */
120
124
  export declare function takeHydrationValue<T = unknown>(key: string): HydrationValue<T> | undefined;
125
+ /**
126
+ * Client stub — a render's link handler is set during server rendering
127
+ * (see the server entry's `setLinkClaim`). Always `false` here, so a router
128
+ * can call it unguarded from isomorphic setup code.
129
+ * @experimental
130
+ */
131
+ export declare function setLinkClaim(_handler: LinkClaimHandler | undefined): boolean;
132
+ /**
133
+ * Whether the server render that produced this document ran a link handler
134
+ * (`setLinkClaim`), so its anchors carry the server's link state
135
+ * (`aria-current="page"`, `data-active`) in the HTML. Reads the `links`
136
+ * hydration record the render wrote once; non-destructive, readable before
137
+ * and after hydration. `false` on a page rendered without the router — the
138
+ * absence of link state on an anchor then means nothing, and a link
139
+ * consumer must resolve it itself. Server: `false`.
140
+ * @experimental
141
+ */
142
+ export declare function hasServerLinkState(): boolean;
121
143
  /**
122
144
  * Client stub — the trace a request belongs to is a server-side reading
123
145
  * (the incoming `traceparent`, the render's origination); the browser SDK
@@ -181,9 +203,37 @@ export declare function unregisterDelegatedContainer(container: MountableElement
181
203
  export declare function dispatchAsInteraction<T>(e: Event, fn: () => T): T;
182
204
  export declare function getDelegatedRoot(node: MountableElement): MountableElement | undefined;
183
205
  export declare function setProperty(node: Element, name: string, value: any): void;
184
- export declare function registerElementClaim(handler: (element: Element) => void): () => void;
206
+ /** Options for `registerElementClaim`. */
207
+ export type ElementClaimOptions = {
208
+ /**
209
+ * Attribute names whose compiler-owned writes re-claim an already claimed
210
+ * element, as plain names: `href` covers the `href` attribute, the
211
+ * `prop:href` property path and the `xlink:href` namespaced path alike.
212
+ * Defaults to `["href", "action"]`. The write sites consult the union of
213
+ * every registered consumer's set.
214
+ */
215
+ attributes?: readonly string[];
216
+ }; /**
217
+ * Register a consumer for compiler-emitted element claims. Compiled DOM
218
+ * output claims navigation-relevant elements (`a[href]`, `form[action]`)
219
+ * once at mount, after their initial attributes are applied — so a handler
220
+ * sees the element's final initial attributes and is told about one mount
221
+ * exactly once. Afterwards compiler-owned writes to an attribute in the
222
+ * consumer's declared set (`options.attributes`, default `href`/`action`;
223
+ * `prop:href` and `xlink:href` map to `href`) re-invoke the handlers — so
224
+ * handlers must be idempotent and must check the element's relevance
225
+ * themselves. Handlers run under the reactive owner the element was created
226
+ * with; scope per-element state and cleanup through your own reactive
227
+ * system. Dormant until registered — without a handler the emitted claims
228
+ * are null checks. Returns an unregister function.
229
+ *
230
+ * Integration plumbing (routers register the consumer); not meant for
231
+ * application code.
232
+ * @internal
233
+ */
234
+ export declare function registerElementClaim(handler: (element: Element) => void, options?: ElementClaimOptions): () => void;
185
235
  export declare function claimElementTree<T extends Node>(root: T): T;
186
- export declare function claimElement<T extends Element>(node: T): T;
236
+ export declare function claimElement<T extends Element>(node: T, owner?: Owner | null): T;
187
237
  export declare function setAttribute(node: Element, name: string, value: string): void;
188
238
  export declare function setAttributeNS(node: Element, namespace: string, name: string, value: string): void;
189
239
  export declare function className(node: Element, value: JSX.ClassValue, prev?: JSX.ClassValue): void;
@@ -208,7 +258,17 @@ export declare function style(node: Element, value: {
208
258
  * literal is already the compute's own); a proxy is copied with ONE
209
259
  * `ownKeys` trap (its own trap keeps the key set tracked) plus one tracked
210
260
  * read per key; a clsx-style class array is re-mapped element-wise (className
211
- * allocates for an array anyway; measured at parity). */
261
+ * allocates for an array anyway; measured at parity).
262
+ *
263
+ * The proxy's keys are read with `Reflect.ownKeys` directly — what
264
+ * `sourceKeys(value, SOURCE_PROXY)` resolves to by definition (`leafOf` is
265
+ * the identity for a proxy kind; `leafKeys` answers a proxy with one
266
+ * `ownKeys` trap) — rather than through `sourceKeys`, whose kind argument is
267
+ * a runtime value: calling it here retained the merge/omit view walkers
268
+ * (`collectKeys`, `mergeKeysOf`, `hiddenByAny`, …, ≈ 1.1 KB minified) on
269
+ * every compiled page with a dynamic `class`/`style`, reached by nothing
270
+ * (hydration-split-measured.md, candidate (e)). `spread()` still reads its
271
+ * sources through `sourceKeys`, so a page with an element spread keeps them. */
212
272
  export declare function readShallow(value: unknown): unknown;
213
273
  /** Compiler-emitted primitive; not for hand-written code. @internal */
214
274
  export declare function setStyleProperty(node: Element, name: string, value: any): void;
@@ -273,5 +333,37 @@ export declare function getNextMarker(start: Node): [Node, Array<Node>];
273
333
  export declare function getFirstChild(node: any, expectedTag: any): any;
274
334
  export declare function getNextSibling(node: any, expectedTag: any): any;
275
335
  export declare function runHydrationEvents(): void;
336
+ /**
337
+ * Installs the server-component half of hydration — solid's
338
+ * (`enableServerComponentHydration`: the hold, the claim window, fragment
339
+ * ownership, the ledger's published answer) and this runtime's two terms of
340
+ * the claim walk:
341
+ *
342
+ * - `sharedConfig.claimRoots` (ruling 95): a claimed tree isn't always IN
343
+ * the document — a frame adoption whose slot fill resolved async claims
344
+ * its server-rendered range after a pending boundary displaced it
345
+ * (re-inserted on reveal). Such claim scopes declare their roots, and
346
+ * descent from one is as claimed as being connected; fresh clones
347
+ * descend from neither.
348
+ * - The root sweep's frame exclusion (ruling 97): frame regions
349
+ * (`data-fid` — the frame runtime's element brand, an importless
350
+ * duplicate like FRAME_ID_ATTR in frame-client/frame-sink) are another
351
+ * layer's property. Their fills claim through their own windows on their
352
+ * own schedule (a lazy route module may adopt long after the root
353
+ * completes), so collecting them in the ambient sweep only sets up the
354
+ * completion sweep to report legitimately-late claims as unclaimed.
355
+ * Whether the root has frames is one question about the page, not one
356
+ * per keyed node: found once per sweep, containment-tested against the
357
+ * list rather than `closest("[data-fid]")` from every node.
358
+ *
359
+ * The same shape as `hydrate()` — solid's half, then this runtime's — one
360
+ * call for the integration. Before `hydrate()` runs its root sweep (the
361
+ * frames client calls it from `installServerComponents()`, which precedes
362
+ * `hydrate()` in every entry) and again wherever it re-attempts its reveal
363
+ * hook; idempotent. Cross-package wiring; not for application code.
364
+ *
365
+ * @internal
366
+ */
367
+ export declare function installServerComponentHydration(): void;
276
368
  export declare function getHydrationKey(): string | undefined;
277
369
  export declare const RequestContext: unique symbol;
@@ -6,6 +6,7 @@
6
6
  */
7
7
  declare const DOMWithState: Record<string, Record<string, 1 | 2>>;
8
8
  declare const ChildProperties: Set<string>;
9
+ declare const LinkAttributes: Set<string>;
9
10
  declare const $$SLOT: unique symbol;
10
11
  declare const $$HOST: unique symbol;
11
12
  declare const DelegatedEvents: Set<string>;
@@ -18,4 +19,4 @@ declare const DOMElements: Set<string>;
18
19
  declare const COMPOSED_BODY_FRAMING: ReadonlySet<string>;
19
20
  declare function isHttpNavigationTarget(target: string): boolean;
20
21
  declare function isEventName(name: string): boolean;
21
- export { DOMWithState, ChildProperties, DelegatedEvents, SVGElements, MathMLElements, VoidElements, RawTextElements, Namespaces, DOMElements, $$SLOT, $$HOST, COMPOSED_BODY_FRAMING, isHttpNavigationTarget, isEventName };
22
+ export { DOMWithState, ChildProperties, LinkAttributes, DelegatedEvents, SVGElements, MathMLElements, VoidElements, RawTextElements, Namespaces, DOMElements, $$SLOT, $$HOST, COMPOSED_BODY_FRAMING, isHttpNavigationTarget, isEventName };
@@ -100,5 +100,5 @@ export type BindingSlot<P = {}, J extends object = Record<string, unknown>> = {}
100
100
  * ```
101
101
  */
102
102
  export declare function asyncArg<T>(value: PromiseLike<T> | AsyncIterable<T>): T;
103
- export { renderToFrameStream, renderServerComponent, serverComponentResponse, frameTransformResult, frameTransformFlightResult, createFrameSink, frameTransformDirectResult, ServerComponentPlugin, SERVER_COMPONENT_BOOTSTRAP } from "./frame-sink.js";
103
+ export { frameTransformResult, frameTransformFlightResult, frameTransformDirectResult, ServerComponentPlugin, SERVER_COMPONENT_BOOTSTRAP } from "./frame-sink.js";
104
104
  export { FRAME_STREAM_HEADER, FRAME_HAVE_HEADER, FRAME_HAVE_BUDGET, FRAME_TIERS_HEADER, isFrameStreamResponse } from "./frame-transport.js";
package/types/head.d.ts CHANGED
@@ -14,6 +14,7 @@ export declare function classifyHeadTag(desc: any): {
14
14
  };
15
15
  export declare function qualifierValue(name: any, value: any): any;
16
16
  export declare function asciiLowerCase(value: any): any;
17
+ export declare function headBodyText(tag: any, props: any, text: any): any;
17
18
  export declare function resourceIdentity(tag: any, props: any): string;
18
19
  export declare function replaceableIdentity(tag: any, props: any, key: any, unique: any): any;
19
20
  export declare function resolveHead(groups: any): Map<any, any>;
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Component } from "solid-js";
1
+ import { Component, type DynamicOptions } from "solid-js";
2
2
  import type { JSX } from "./jsx.js";
3
3
  export * from "./client.js";
4
4
  export * from "./server-mock.js";
@@ -79,21 +79,61 @@ export declare function Portal(props: {
79
79
  mount?: Element;
80
80
  children: JSX.Element;
81
81
  }): JSX.Element;
82
- export interface DynamicOptions {
83
- /**
84
- * SSR only: hold the document's first flush until the source settles, so
85
- * the resolved component renders into the shell instead of streaming in
86
- * behind its boundary's fallback. Same meaning as `createMemo`'s
87
- * `deferStream`. Ignored on the client.
88
- */
89
- deferStream?: boolean;
90
- /**
91
- * The source cannot change: call it once, untracked, now, and render the
92
- * result with no computation per instance (see `dynamic`). The source must
93
- * resolve synchronously.
94
- */
95
- static?: boolean;
96
- }
82
+ export type { DynamicOptions } from "solid-js";
83
+ export { dynamicComponent } from "solid-js";
84
+ /**
85
+ * Returns a stable `Component` whose identity is driven by a reactive (and
86
+ * optionally async) `source`. The returned component can be used anywhere a
87
+ * normal component is used; children and props flow through JSX as usual.
88
+ *
89
+ * `source` may return a component, a native tag name (`'input'`, `'textarea'`,
90
+ * etc.), `undefined`, or a `Promise` of any of the above. A pending promise
91
+ * propagates as `NotReadyError` through the surrounding reactive scope, so
92
+ * async swaps compose with `<Loading>` boundaries the same way as `lazy`.
93
+ *
94
+ * During SSR a pending source streams in behind its boundary by default. Pass
95
+ * `{ deferStream: true }` to hold the document's first flush until it settles
96
+ * (the same option `createMemo` takes); the client ignores it.
97
+ *
98
+ * For a tag-name source the element's namespace is inferred from the tag. A
99
+ * tag that exists in both HTML and SVG (`a`, `script`, `style`, `title`) is
100
+ * created as HTML unless the instance passes `xmlns` — the same attribute
101
+ * compiled JSX uses for the same purpose. `is` (customized built-ins) and
102
+ * `xmlns` are read once at creation and then applied as ordinary attributes.
103
+ *
104
+ * `{ static: true }` says the source cannot change: it is called once,
105
+ * untracked, when `dynamic()` is called, and each instance renders the result
106
+ * with no computation of its own — a tag name goes straight to the compiled
107
+ * element path (create or claim, spread), a component is called directly. No
108
+ * owner is created on either side, so hydration keys stay aligned with the
109
+ * compiled output. Use it for a constant (`dynamic(() => "li", { static: true })`
110
+ * in a runtime `styled()`), or per instance from the shape of a prop:
111
+ * `isStatic(props, "as")` is true when the caller wrote `as="button"`
112
+ * (a data property) and false when they wrote `as={cond() ? …}` (a getter),
113
+ * so a polymorphic component keeps a reactive public `as` and still pays
114
+ * nothing for the literal case. A static source may not return a promise.
115
+ *
116
+ * @example
117
+ * ```tsx
118
+ * // `source` can return either a custom Component or a native tag
119
+ * // name — they're interchangeable, and the returned reference is a
120
+ * // stable Component you can use anywhere a normal one would go.
121
+ * const Field = dynamic(() => multiline() ? RichTextEditor : "input");
122
+ * return <Field value={value()} onInput={onInput} />;
123
+ *
124
+ * // An ambiguous tag inside an SVG tree: say which namespace you mean.
125
+ * const Link = dynamic(() => "a");
126
+ * <svg><Link xmlns="http://www.w3.org/2000/svg" href="/x">…</Link></svg>
127
+ *
128
+ * // A polymorphic component: no memo when `as` arrived as a literal.
129
+ * function Polymorphic(props) {
130
+ * const Tag = dynamic(() => props.as, { static: isStatic(props, "as") });
131
+ * return <Tag {...omit(props, "as")} />;
132
+ * }
133
+ * ```
134
+ *
135
+ * @description https://docs.solidjs.com/reference/components/dynamic
136
+ */
97
137
  /**
98
138
  * A component from a reactive source. The source may answer with the
99
139
  * component itself, a promise of it, or an async iterable of it — a `live`
@@ -115,39 +155,6 @@ export interface DynamicOptions {
115
155
  * component mount — should use `dynamicComponent`, which never does.
116
156
  */
117
157
  export declare function dynamic<T extends ValidComponent>(source: () => T | Promise<T> | AsyncIterable<T> | null | undefined | false, options?: DynamicOptions): Component<ComponentProps<T>>;
118
- /**
119
- * `dynamic` for a source that only ever answers with a component — never a
120
- * tag name. Same contract, same semantics, same hydration shape (the two
121
- * share one implementation): a reactive, optionally async source; a stable
122
- * `Component` back; `{ static: true }` and `{ deferStream: true }` as on
123
- * `dynamic`. The source's type excludes strings, so a tag name is a compile
124
- * error here — use `dynamic` for one.
125
- *
126
- * Cost model, which is the reason this exists: `dynamic` must be able to
127
- * render a tag, so one `dynamic` anywhere on a page retains the element
128
- * runtime — `createElement`, `spread` and the prop-collection helpers, the
129
- * SVG/MathML tables — for everyone, whether or not any source ever answers
130
- * with a string (a bundler cannot know what a source will resolve to).
131
- * `dynamicComponent` has no tag arm and never references that runtime, so a
132
- * page whose only dynamic mounts are components pays nothing for it.
133
- *
134
- * This is the documented way to mount a server component: a server
135
- * function's answer is a component reference, and the frames transport
136
- * resolves every call for the same function to the same mount identity, so
137
- * a refetch or an argument change is delivered into the mounted instance
138
- * rather than remounting it (see `dynamic` for the full account).
139
- *
140
- * @example
141
- * ```tsx
142
- * const Story = dynamicComponent(() => getStory(props.storyId));
143
- * return <Story comment={p => <Comment cid={p.cid}>{p.children}</Comment>} />;
144
- *
145
- * // A client component chosen by (sync) data — the same thing `dynamic`
146
- * // does, without retaining the element runtime for the page.
147
- * const Page = dynamicComponent(() => (page().editable ? Editor : Viewer));
148
- * ```
149
- */
150
- export declare function dynamicComponent<C extends Component<any>>(source: () => C | Promise<C> | AsyncIterable<C> | null | undefined | false, options?: DynamicOptions): Component<ComponentProps<C>>;
151
158
  /**
152
159
  * @deprecated Use `dynamic()`. `<Dynamic>` is the same primitive, but its
153
160
  * shape puts the tag in the same bag as the element's props: every instance
@@ -1,4 +1,4 @@
1
- import { type Component } from "solid-js";
1
+ import { type Component, type DynamicOptions } from "solid-js";
2
2
  import type { JSX } from "./jsx.js";
3
3
  export * from "./server.js";
4
4
  export * from "./response.js";
@@ -25,33 +25,9 @@ export declare const isDev: boolean;
25
25
  export type IntrinsicElement = Extract<keyof JSX.IntrinsicElements, string>;
26
26
  export type ValidComponent = IntrinsicElement | Component<any> | (string & {});
27
27
  export type ComponentProps<T extends ValidComponent> = T extends Component<infer P> ? P : T extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[T] : Record<string, unknown>;
28
- export interface DynamicOptions {
29
- /**
30
- * SSR only: hold the document's first flush until the source settles, so
31
- * the resolved component renders into the shell instead of streaming in
32
- * behind its boundary's fallback. Same meaning as `createMemo`'s
33
- * `deferStream`. Default `false` — a `dynamic()` source is data of unknown
34
- * cost and streams by default (a code-split `lazy()` always holds the shell
35
- * for its module load, since its code is a prerequisite to the render).
36
- */
37
- deferStream?: boolean;
38
- /**
39
- * The source cannot change: call it once, untracked, now, and render the
40
- * result with no computation per instance (see the client `dynamic`). The
41
- * source must resolve synchronously.
42
- */
43
- static?: boolean;
44
- }
28
+ export type { DynamicOptions } from "solid-js";
29
+ export { dynamicComponent } from "solid-js";
45
30
  export declare function dynamic<T extends ValidComponent>(source: () => T | Promise<T> | null | undefined | false, options?: DynamicOptions): Component<ComponentProps<T>>;
46
- /**
47
- * The server twin of the client's `dynamicComponent`: `dynamic` for a source
48
- * that only ever answers with a component, never a tag name. Same owner
49
- * shape as `dynamic` on both sides (the factory / value / render memos), so
50
- * hydration ids agree with the client whichever of the two mounts the same
51
- * value. The client entry's JSDoc carries the cost model; here the tag arm
52
- * is simply absent.
53
- */
54
- export declare function dynamicComponent<C extends Component<any>>(source: () => C | Promise<C> | null | undefined | false, options?: DynamicOptions): Component<ComponentProps<C>>;
55
31
  /** @deprecated Props of the deprecated `<Dynamic>`; see `dynamic()`. */
56
32
  export type DynamicProps<T extends ValidComponent, P = ComponentProps<T>> = {
57
33
  [K in keyof P]: P[K];
package/types/jsx.d.ts CHANGED
@@ -1139,20 +1139,11 @@ export namespace JSX {
1139
1139
  target?: "_self" | "_blank" | "_parent" | "_top" | (string & {}) | RemoveAttribute;
1140
1140
  type?: string | RemoveAttribute;
1141
1141
 
1142
- // Client-side navigation contract. These attributes are inert markup on
1143
- // their own — a routing integration that delegates anchor clicks (e.g.
1144
- // @solidjs/router) reads them off the element at event time. Typed here
1145
- // so plain `<a>` elements participate without per-router augmentation.
1142
+ // Client-side navigation contract. `link` is inert markup on its own —
1143
+ // a routing integration that delegates anchor clicks (e.g. @solidjs/router)
1144
+ // reads it off the element at event time.
1146
1145
  /** Marks the anchor as a client-navigation link when the integration requires explicit opt-in. */
1147
1146
  link?: BooleanAttribute | RemoveAttribute;
1148
- /** Serialized (JSON) history state pushed alongside the navigation. */
1149
- state?: string | RemoveAttribute;
1150
- /** Suppress scroll restoration/reset after the navigation. */
1151
- noscroll?: BooleanAttribute | RemoveAttribute;
1152
- /** Replace the current history entry instead of pushing a new one. */
1153
- replace?: BooleanAttribute | RemoveAttribute;
1154
- /** Route preload intent; `"false"` disables the integration's default eager preload. */
1155
- preload?: boolean | "false" | RemoveAttribute;
1156
1147
 
1157
1148
  /** @experimental */
1158
1149
  attributionsrc?: string | RemoveAttribute;
@@ -4,8 +4,14 @@
4
4
  * payloads); the HTTP handler forwards `response`'s headers and
5
5
  * (non-redirect) status and encodes `value` as the body through the codec,
6
6
  * while client-only integrations read `value` directly — no reparse.
7
+ *
8
+ * The envelope IS a `Response` — the given response's body, status and
9
+ * headers — so a consumer that knows nothing of Solid (a filesystem
10
+ * router's API dispatch, any fetch-style handler) answers with it as-is.
11
+ * `response` is the envelope itself, or `undefined` when constructed
12
+ * without one.
7
13
  */
8
- export interface ResponseEnvelope<T = unknown> {
14
+ export interface ResponseEnvelope<T = unknown> extends Response {
9
15
  response: Response | undefined;
10
16
  value: T;
11
17
  }
@@ -73,13 +79,24 @@ export declare const RESPONSE_HEADER_VALUE_LIMIT = 4096;
73
79
  /**
74
80
  * Response redirecting to `url` (default 302). `revalidate` names the
75
81
  * cache keys the mutation invalidated.
82
+ *
83
+ * Typed so it never shows up in the type of the function returning it: a
84
+ * redirect is control flow for the integration to act on, not a value.
85
+ * `T` defaults to `never`, which vanishes from the inferred return type's
86
+ * union; where the context expects a type (an annotated return, a
87
+ * `Response`-typed request handler) `T` takes it. A literal `never` return
88
+ * would also mark code after a bare call unreachable; a type parameter
89
+ * does not. At runtime it is a real `Response`.
76
90
  */
77
- export declare function redirect(url: string | Href, init?: number | ResponseHelperInit): Response;
91
+ export declare function redirect<T = never>(url: string | Href, init?: number | ResponseHelperInit): T;
78
92
  /**
79
93
  * Empty response requesting revalidation of the named cache keys (all of
80
94
  * them when omitted).
95
+ *
96
+ * Typed as `redirect` is, for the same reason: it never shows up in the
97
+ * type of the function returning it. At runtime it is a real `Response`.
81
98
  */
82
- export declare function reload(init?: ResponseHelperInit): Response;
99
+ export declare function reload<T = never>(init?: ResponseHelperInit): T;
83
100
  /**
84
101
  * Statuses HTTP forbids a body on — the `Response` constructor enforces it
85
102
  * by throwing on ANY body, `JSON.stringify(undefined)`'s `"undefined"`
@@ -95,5 +112,10 @@ export declare const NULL_BODY_STATUSES: ReadonlySet<number>;
95
112
  * stays invisible: the carried response holds a plain JSON body so
96
113
  * consumers without the client runtime (no-JS form posts, direct HTTP)
97
114
  * get real JSON, while integrations read `value` — no reparse.
115
+ *
116
+ * Typed as `value`'s type: every caller of the function returning it —
117
+ * over HTTP or in-process — receives the value, never the envelope. At
118
+ * runtime it is a `ResponseEnvelope`, a real `Response` that integrations
119
+ * recognize with `isResponseEnvelope()`.
98
120
  */
99
- export declare function respond<T>(value: T, init?: ResponseHelperInit): ResponseEnvelope<T>;
121
+ export declare function respond<T>(value: T, init?: ResponseHelperInit): T;
@@ -98,6 +98,10 @@ export interface ServerFunctionsClientConfig {
98
98
  * }
99
99
  * });
100
100
  * ```
101
+ *
102
+ * Return synchronously when you can: hydration adopts a server-rendered
103
+ * read only if its request is sent in the same tick, so an async hook
104
+ * makes every hydrated read fetch again from the browser.
101
105
  */
102
106
  prepareRequest?: PrepareRequestHook;
103
107
  /**
@@ -271,7 +271,7 @@ export declare function getExpectedRedirectStatus(response: ResponseStub): numbe
271
271
  */
272
272
  export declare function createSSRResponse(result: string, event: RequestEvent | undefined, options?: {
273
273
  responseInit?: ResponseInit;
274
- nonce?: string;
274
+ nonce?: CSPNonce;
275
275
  transformChunk?: (chunk: string) => string;
276
276
  }): Response;
277
277
  export declare function createSSRResponse(result: {
@@ -281,7 +281,7 @@ export declare function createSSRResponse(result: {
281
281
  }): void;
282
282
  }, event: RequestEvent | undefined, options?: {
283
283
  responseInit?: ResponseInit;
284
- nonce?: string;
284
+ nonce?: CSPNonce;
285
285
  transformChunk?: (chunk: string) => string;
286
286
  }): Promise<Response>;
287
287
  /**
@@ -325,6 +325,13 @@ export declare function ssrElement(name: string, props: any | any[] | (() => any
325
325
  * @internal
326
326
  */
327
327
  export declare function ssrElementAttribute(key: string, value: any): string;
328
+ /**
329
+ * Compiler primitive — the hole after a candidate anchor's attributes in SSR
330
+ * output, the render's link handler's markup (see the server entry's
331
+ * `setLinkClaim`). Not meant for hand-written code.
332
+ * @internal
333
+ */
334
+ export declare function ssrLinkClaim(attrs: Readonly<Record<string, unknown>>): string;
328
335
  /**
329
336
  * Compiler primitive — serializes a class value (string, object map, or
330
337
  * array) for SSR output. Not meant for hand-written code.