@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.
package/types/server.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { getOwner, createComponent, untrack, merge as mergeProps } from "solid-js";
2
2
  import { sharedConfig, ssrScope as scope } from "solid-js/internal";
3
+ import type { Owner } from "solid-js";
3
4
  import type { ServerErrorSite } from "solid-js/internal";
4
5
  import { effect, memo } from "./render.js";
5
6
  import { type TraceContext } from "./trace.js";
@@ -106,9 +107,9 @@ export type AssetResolverFn = (key: string) => ResolvedAssets | null | undefined
106
107
  * fallback reaches `script-src`. A nonce on a `useHead` tag's own props
107
108
  * always wins.
108
109
  *
109
- * Only `renderToString` / `renderToStream` take this shape. Surfaces that
110
- * emit one script (`HydrationScript`, `generateHydrationScript`,
111
- * `createSSRResponse`) take a string — project with `scriptNonce`.
110
+ * Surfaces that emit one script (`HydrationScript`,
111
+ * `generateHydrationScript`, `createSSRResponse`) take either shape and use
112
+ * its script half.
112
113
  */
113
114
  export type CSPNonce = string | {
114
115
  script: string | false;
@@ -203,8 +204,8 @@ export type { ServerFunction, ServerFunctionMetadata, ServerFunctionRPC } from "
203
204
  export interface SSRResponseOptions {
204
205
  /** Base head; the stub's status/headers win over it. */
205
206
  responseInit?: ResponseInit;
206
- /** Nonce carried by the post-flush `<script>` redirect fallback. */
207
- nonce?: string;
207
+ /** Nonce carried by the post-flush `<script>` redirect fallback (its script half). */
208
+ nonce?: CSPNonce;
208
209
  /** Rewrites each outgoing HTML chunk (entry script injection, ...). */
209
210
  transformChunk?: (chunk: string) => string;
210
211
  }
@@ -217,7 +218,18 @@ export type FetchMiddleware = (request: Request, next: (request?: Request) => Pr
217
218
  export { createComponent, effect, memo, untrack, mergeProps, scope, getOwner };
218
219
  export { sharedConfig };
219
220
  export { DOMWithState, ChildProperties, DOMElements, SVGElements, MathMLElements, VoidElements, RawTextElements, Namespaces, DelegatedEvents } from "./constants.js";
221
+ /**
222
+ * The script half of a `CSPNonce`. The surfaces that emit one script take a
223
+ * `CSPNonce` and project it themselves; this stays exported only for
224
+ * `@solidjs/vite-plugin`'s generated handler, which still imports it.
225
+ * @internal
226
+ */
220
227
  export declare function scriptNonce(nonce?: CSPNonce): string | undefined;
228
+ /**
229
+ * The style half of a `CSPNonce`. Exported only for
230
+ * `@solidjs/vite-plugin`'s generated handler, which still imports it.
231
+ * @internal
232
+ */
221
233
  export declare function styleNonce(nonce?: CSPNonce): string | undefined;
222
234
  export declare function useHead(tag: HeadTag | HeadTag[] | (() => HeadTag | HeadTag[])): void;
223
235
  export declare function renderToString<T>(fn: () => T, options?: {
@@ -331,7 +343,7 @@ export declare function renderToStream<T>(fn: () => T, options?: {
331
343
  readonly readable: ReadableStream<Uint8Array>;
332
344
  };
333
345
  export declare function HydrationScript(props: {
334
- nonce?: string;
346
+ nonce?: CSPNonce;
335
347
  eventNames?: string[];
336
348
  }): JSX.Element;
337
349
  export declare function ssrGroup<T extends () => any[]>(fn: T, n: number): T;
@@ -444,13 +456,33 @@ export declare function slotValue(occurrence: string, key: string, value: unknow
444
456
  * replay-window stamp beside its markers (`eventSlotStamp`).
445
457
  */
446
458
  export declare function ssrClaim(map: Record<string, unknown>): string;
459
+ /**
460
+ * A render's link handler (`setLinkClaim`): given an anchor's link-relevant
461
+ * attributes — `href`, and `target` / `rel` / `download` / `link` /
462
+ * `aria-current` when present, raw values as written — returns the extra
463
+ * attribute markup for the anchor, each attribute with its leading space
464
+ * (`" data-active"`, `' data-active aria-current="page"'`), or `""`.
465
+ * Synchronous and pure; the markup is the handler's own and is written
466
+ * verbatim.
467
+ * @experimental
468
+ */
469
+ export type LinkClaimHandler = (attrs: Readonly<Record<string, unknown>>) => string;
470
+ /**
471
+ * Compiler-emitted hole after a candidate anchor's attributes in SSR output:
472
+ * the render's link handler's markup for the anchor (`setLinkClaim`), or
473
+ * `""` when the render has no handler. An author-written `aria-current`
474
+ * wins — the handler is not consulted for that anchor. Not for hand-written
475
+ * code.
476
+ * @internal
477
+ */
478
+ export declare function ssrLinkClaim(attrs: Readonly<Record<string, unknown>>): string;
447
479
  export declare function ssrSelectValues(): void;
448
480
  export declare function resolveSSRSelectValues(html: any): any;
449
481
  export declare function escape(s: any, attr?: boolean): any;
450
482
  export declare function getHydrationKey(): string | undefined;
451
483
  export declare function applyRef(r: ((element: any) => void) | ((element: any) => void)[], element: any): void;
452
484
  export declare function generateHydrationScript(options?: {
453
- nonce?: string;
485
+ nonce?: CSPNonce;
454
486
  eventNames?: string[];
455
487
  }): string;
456
488
  export declare function resolveSSRNode(node: any, result?: any, top?: boolean, nested?: boolean): any;
@@ -595,6 +627,38 @@ export type HydrationValue<T = unknown> = {
595
627
  * ```
596
628
  */
597
629
  export declare function getHydrationWriter(): HydrationWriter | undefined;
630
+ /**
631
+ * Sets the link handler of the render the caller belongs to — found through
632
+ * the caller's owner (component setup), else through the request scope when
633
+ * exactly one render is open for it — so every candidate anchor rendered
634
+ * from here on carries the handler's markup (`aria-current="page"`,
635
+ * `data-active`) in the server HTML. Returns `false` outside any render.
636
+ *
637
+ * Scoped to the render: concurrent renders never share a handler, and it is
638
+ * gone with the render. Set once per render, typically from a router's
639
+ * server render with its request's location; `undefined` clears it. Anchors
640
+ * serialized BEFORE the call (a document shell above the router) are not
641
+ * marked. Server components inline in the document render under the page's
642
+ * handler; a server component's own frame stream has none unless its render
643
+ * sets one.
644
+ *
645
+ * The first call with a handler writes the `links` hydration record once for
646
+ * the response (`hasServerLinkState()` on the client), the signal that the
647
+ * anchors' link state is the server's and can be trusted at hydration.
648
+ *
649
+ * @example
650
+ * ```ts
651
+ * // in <Router>'s server render
652
+ * setLinkClaim(attrs => matchLink(attrs, location) ? ' data-active aria-current="page"' : "");
653
+ * ```
654
+ * @experimental
655
+ */
656
+ export declare function setLinkClaim(handler: LinkClaimHandler | undefined): boolean;
657
+ /**
658
+ * Server: `false`. The client reads the `links` hydration record a render
659
+ * with a link handler wrote (`setLinkClaim`); see the client entry.
660
+ */
661
+ export declare function hasServerLinkState(): boolean;
598
662
  /** Server stub — the registry is the client's. See the client entry. */
599
663
  export declare function takeHydrationValue<T = unknown>(_key: string): HydrationValue<T> | undefined;
600
664
  /**
@@ -627,8 +691,20 @@ export declare function createSSRResponse(result: {
627
691
  }): void;
628
692
  }, event: RequestEvent | undefined, options?: SSRResponseOptions): Promise<Response>;
629
693
  export declare function composeMiddleware(middlewares: FetchMiddleware[]): (request: Request, next: (request?: Request) => Response | Promise<Response>) => Promise<Response>;
630
- export declare function registerElementClaim(handler: (element: Element) => void): () => void;
631
- export declare function claimElement<T extends Element>(node: T): T;
694
+ /** Options for `registerElementClaim` (see the client entry); inert on the server. */
695
+ export type ElementClaimOptions = {
696
+ /**
697
+ * Attribute names whose compiler-owned writes re-claim an already claimed
698
+ * element, as plain names (`href` covers `prop:href` and `xlink:href`).
699
+ * Defaults to `["href", "action"]`.
700
+ */
701
+ attributes?: readonly string[];
702
+ }; /**
703
+ * Server no-op: element claims are a client-only concern, but consumers may
704
+ * register isomorphically. Returns a no-op unregister function.
705
+ */
706
+ export declare function registerElementClaim(handler: (element: Element) => void, options?: ElementClaimOptions): () => void;
707
+ export declare function claimElement<T extends Element>(node: T, owner?: Owner | null): T;
632
708
  export declare function claimElementTree<T extends Node>(root: T): T;
633
709
  /** Server: `fn()`. No event is dispatched during SSR, so there is no interaction to join. */
634
710
  export declare function dispatchAsInteraction<T>(_e: Event, fn: () => T): T;