@solidjs/web 2.0.0-beta.17 → 2.0.0-beta.18

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.
@@ -118,6 +118,12 @@ export declare const hydrate: typeof hydrateCore;
118
118
  * still participates in the parent's reactive scope and disposes when the
119
119
  * parent does.
120
120
  *
121
+ * Portals are client-only islands: the server renders nothing for them, and
122
+ * under hydration the children render fresh once hydration settles. Async
123
+ * read inside a portal therefore starts on the client — data that should be
124
+ * fetched on the server belongs above the portal (hoist the read, not the
125
+ * render), and async UI inside one wants its own `<Loading>` boundary.
126
+ *
121
127
  * @example
122
128
  * ```tsx
123
129
  * <Portal mount={document.getElementById("modal-root")!}>
@@ -127,7 +133,7 @@ export declare const hydrate: typeof hydrateCore;
127
133
  *
128
134
  * @description https://docs.solidjs.com/reference/components/portal
129
135
  */
130
- export declare function Portal<T extends boolean = false, S extends boolean = false>(props: {
136
+ export declare function Portal(props: {
131
137
  mount?: Element;
132
138
  children: JSX.Element;
133
139
  }): JSX.Element;
@@ -0,0 +1,97 @@
1
+ import { Plugin, Serializer, SerovalNode } from "seroval";
2
+
3
+ export type { SerovalNode };
4
+
5
+ /** A Seroval plugin usable with the web serializers. */
6
+ export type SerializerPlugin = Plugin<any, any>;
7
+
8
+ /**
9
+ * Baseline plugin set for serializing web-platform values (AbortSignal,
10
+ * Event, FormData, Headers, ReadableStream, Request, Response, URL, ...).
11
+ */
12
+ export const DEFAULT_WEB_PLUGINS: readonly SerializerPlugin[];
13
+
14
+ /**
15
+ * Composes custom plugins with `DEFAULT_WEB_PLUGINS`. Custom plugins come
16
+ * first so they can shadow a default for values both would match. Returns a
17
+ * fresh array; the defaults are never mutated.
18
+ */
19
+ export function resolveSerializerPlugins(customPlugins?: SerializerPlugin[]): SerializerPlugin[];
20
+
21
+ export interface WebSerializerOptions {
22
+ /** Name of the global object the emitted scripts write resolved values into. */
23
+ globalIdentifier: string;
24
+ scopeId?: string;
25
+ /**
26
+ * Seroval feature bitflags to exclude from output. Defaults to disabling
27
+ * post-ES2017 features (AggregateError, BigInt typed arrays).
28
+ */
29
+ disabledFeatures?: number;
30
+ /** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. */
31
+ plugins?: SerializerPlugin[];
32
+ onData: (result: string) => void;
33
+ onError?: (error: unknown) => void;
34
+ onDone?: () => void;
35
+ }
36
+
37
+ /**
38
+ * Creates a streaming Seroval serializer preconfigured with the web plugin
39
+ * set and the default feature policy.
40
+ */
41
+ export function createSerializer(options: WebSerializerOptions): Serializer;
42
+
43
+ export type HydrationSerializerOptions = Omit<
44
+ WebSerializerOptions,
45
+ "globalIdentifier" | "disabledFeatures"
46
+ >;
47
+
48
+ /**
49
+ * Serializer for SSR hydration output. Pins the hydration global (`_$HY.r`)
50
+ * and feature policy — only the wiring options (callbacks, scope, extra
51
+ * plugins) are configurable.
52
+ */
53
+ export function createHydrationSerializer(options: HydrationSerializerOptions): Serializer;
54
+
55
+ /** Returns the cross-reference bootstrap script for a render scope. */
56
+ export function getLocalHeaderScript(id?: string): string;
57
+
58
+ // ---- JSON codec (server function transports) ----
59
+
60
+ export interface JSONCodecOptions {
61
+ /** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. Must match on both peers. */
62
+ plugins?: SerializerPlugin[];
63
+ /**
64
+ * Seroval feature bitflags to exclude. Defaults to disabling `RegExp`
65
+ * (payloads may come from an untrusted peer). Must match on both peers.
66
+ */
67
+ disabledFeatures?: number;
68
+ /** Maximum parse/deserialize depth. Defaults to 64. Must match on both peers. */
69
+ depthLimit?: number;
70
+ }
71
+
72
+ export interface JSONSerializeOptions extends JSONCodecOptions {
73
+ /**
74
+ * Receives each serialized node; `initial` is true for the first chunk
75
+ * (the source value itself). Async values produce additional chunks as
76
+ * they resolve.
77
+ */
78
+ onParse: (node: SerovalNode, initial: boolean) => void;
79
+ onError?: (error: unknown) => void;
80
+ /** Fires once all async values have settled. */
81
+ onDone?: () => void;
82
+ }
83
+
84
+ /**
85
+ * Serializes `value` as SerovalNode chunks delivered through `onParse`.
86
+ * Wire framing of the nodes is the transport's concern. Returns a cancel
87
+ * function that aborts pending async serialization.
88
+ */
89
+ export function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
90
+
91
+ /**
92
+ * Creates the decoding counterpart of `serializeJSON`. Cross-references
93
+ * between chunks resolve through state shared across calls, so all chunks
94
+ * from one stream must go through the same deserializer instance. The first
95
+ * chunk's return value is the decoded source value.
96
+ */
97
+ export function createJSONDeserializer(options?: JSONCodecOptions): <T>(node: SerovalNode) => T;
@@ -1,4 +1,5 @@
1
1
  import { JSX } from "./jsx.cjs";
2
+ import { SerializerPlugin } from "./serializer.cjs";
2
3
  export const DOMWithState: Record<string, Record<string, 1 | 2>>;
3
4
  export const ChildProperties: Set<string>;
4
5
  export const DelegatedEvents: Set<string>;
@@ -11,17 +12,59 @@ export const Namespaces: Record<string, string>;
11
12
 
12
13
  type MountableElement = Element | Document | ShadowRoot | DocumentFragment | Node;
13
14
 
15
+ /** Static asset manifest produced by a build (e.g. parsed Vite manifest.json). */
16
+ export type AssetManifest = Record<
17
+ string,
18
+ { file: string; css?: string[]; isEntry?: boolean; imports?: string[] }
19
+ > & { _base?: string };
20
+
21
+ /** Inline style content, e.g. dev CSS collected from a bundler's module graph. */
22
+ export type InlineStyleAsset = {
23
+ id: string;
24
+ content: string;
25
+ attrs?: Record<string, string>;
26
+ };
27
+
28
+ export type ResolvedAssets = {
29
+ js: string[];
30
+ css: (string | InlineStyleAsset)[];
31
+ };
32
+
33
+ /**
34
+ * Resolver form of the manifest option — the primitive a dev server
35
+ * implements against its live module graph (a static manifest object is
36
+ * normalized into a sync resolver internally). `resolve` may return a
37
+ * promise (async resolvers require streaming rendering); CSS entries may be
38
+ * URL strings (emitted as load-gated `<link>` tags) or inline-style
39
+ * descriptors (emitted as `<style>` tags). A bare `resolve`-shaped function
40
+ * is accepted as shorthand for `{ resolve }`.
41
+ */
42
+ export type AssetResolver = {
43
+ resolve(
44
+ key: string
45
+ ): ResolvedAssets | null | undefined | Promise<ResolvedAssets | null | undefined>;
46
+ /**
47
+ * Synchronous fast path answering with whatever is knowable without async
48
+ * work (typically js URLs, omitting css). Sync consumers — e.g. a lazy
49
+ * component's `moduleUrl` getter used by islands — use this when `resolve`
50
+ * would return a promise, so adapters should provide it whenever possible.
51
+ */
52
+ resolveSync?(key: string): ResolvedAssets | null | undefined;
53
+ };
54
+
55
+ /** Bare-function shorthand for `AssetResolver` (no sync fast path). */
56
+ export type AssetResolverFn = (
57
+ key: string
58
+ ) => ResolvedAssets | null | undefined | Promise<ResolvedAssets | null | undefined>;
59
+
14
60
  export function renderToString<T>(
15
61
  fn: () => T,
16
62
  options?: {
17
63
  nonce?: string;
18
64
  renderId?: string;
19
65
  noScripts?: boolean;
20
- plugins?: any[];
21
- manifest?: Record<
22
- string,
23
- { file: string; css?: string[]; isEntry?: boolean; imports?: string[] }
24
- > & { _base?: string };
66
+ plugins?: SerializerPlugin[];
67
+ manifest?: AssetManifest | AssetResolver | AssetResolverFn;
25
68
  onError?: (err: any) => void;
26
69
  }
27
70
  ): string;
@@ -33,11 +76,8 @@ export function renderToStringAsync<T>(
33
76
  nonce?: string;
34
77
  renderId?: string;
35
78
  noScripts?: boolean;
36
- plugins?: any[];
37
- manifest?: Record<
38
- string,
39
- { file: string; css?: string[]; isEntry?: boolean; imports?: string[] }
40
- > & { _base?: string };
79
+ plugins?: SerializerPlugin[];
80
+ manifest?: AssetManifest | AssetResolver | AssetResolverFn;
41
81
  onError?: (err: any) => void;
42
82
  }
43
83
  ): Promise<string>;
@@ -47,11 +87,8 @@ export function renderToStream<T>(
47
87
  nonce?: string;
48
88
  renderId?: string;
49
89
  noScripts?: boolean;
50
- plugins?: any[];
51
- manifest?: Record<
52
- string,
53
- { file: string; css?: string[]; isEntry?: boolean; imports?: string[] }
54
- > & { _base?: string };
90
+ plugins?: SerializerPlugin[];
91
+ manifest?: AssetManifest | AssetResolver | AssetResolverFn;
55
92
  onCompleteShell?: (info: { write: (v: string) => void }) => void;
56
93
  onCompleteAll?: (info: { write: (v: string) => void }) => void;
57
94
  onError?: (err: any) => void;
@@ -1 +0,0 @@
1
- export * from "@dom-expressions/runtime/src/client.js";
@@ -1,171 +0,0 @@
1
- import { hydrate as hydrateCore } from "./client.js";
2
- import { Component } from "solid-js";
3
- import type { JSX } from "./jsx.js";
4
- export * from "./client.js";
5
- export * from "./server-mock.js";
6
- export type { JSX } from "./jsx.js";
7
- export { For, Show, Switch, Match, Errored, Loading, Repeat, Reveal, NoHydration, Hydration } from "solid-js";
8
- import { merge } from "solid-js";
9
- /**
10
- * Compiler-emitted prop-spread helper. The JSX transform (in
11
- * `dom-expressions`) emits `mergeProps(...)` calls when compiling prop
12
- * spreads on components — it is *not* a user-facing API. Application code
13
- * should import `merge` from `solid-js` directly.
14
- *
15
- * @internal
16
- */
17
- export declare const mergeProps: typeof merge;
18
- /**
19
- * Build-time constant indicating whether code is running on the server. This
20
- * client entry sets it to `false`; the matching server entry (`@solidjs/web`
21
- * resolved through the `solid` server export condition) sets it to `true`.
22
- *
23
- * Bundlers can dead-code-eliminate branches gated on `isServer`, so guarding
24
- * browser-only code with `if (!isServer) {…}` keeps it out of the SSR bundle
25
- * entirely.
26
- *
27
- * @example
28
- * ```ts
29
- * import { isServer } from "@solidjs/web";
30
- *
31
- * if (!isServer) {
32
- * // Browser-only: tree-shaken out of the SSR bundle.
33
- * window.addEventListener("resize", onResize);
34
- * }
35
- * ```
36
- */
37
- export declare const isServer: boolean;
38
- /**
39
- * Build-time constant indicating whether code is running in a dev build.
40
- * Replaced statically (`_SOLID_DEV_`) by the bundler integration, so guards
41
- * like `if (isDev) {…}` are stripped from production builds.
42
- *
43
- * Use this to gate dev-only diagnostics, warnings, or expensive invariants
44
- * that should never ship to production.
45
- *
46
- * @example
47
- * ```ts
48
- * import { isDev } from "@solidjs/web";
49
- *
50
- * if (isDev) {
51
- * console.warn("debug-only path");
52
- * }
53
- * ```
54
- */
55
- export declare const isDev: boolean;
56
- type MountableElement = Element | Document | ShadowRoot | DocumentFragment | Node;
57
- export type IntrinsicElement = Extract<keyof JSX.IntrinsicElements, string>;
58
- export type ValidComponent = IntrinsicElement | Component<any> | (string & {});
59
- export type ComponentProps<T extends ValidComponent> = T extends Component<infer P> ? P : T extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[T] : Record<string, unknown>;
60
- export type DynamicProps<T extends ValidComponent, P = ComponentProps<T>> = {
61
- [K in keyof P]: P[K];
62
- } & {
63
- component: T | null | undefined | false;
64
- };
65
- /**
66
- * Renders a component tree into a DOM element. Returns a dispose function
67
- * that tears the tree down and cleans up reactive scopes when called.
68
- *
69
- * @example
70
- * ```tsx
71
- * import { render } from "@solidjs/web";
72
- *
73
- * const dispose = render(() => <App />, document.getElementById("root")!);
74
- *
75
- * // Later, to unmount:
76
- * dispose();
77
- * ```
78
- *
79
- * @remarks
80
- * The top-level insert is queued via `insertOptions: { schedule: true }` so
81
- * its initial DOM attach goes through the effect queue rather than executing
82
- * inline. This lets the mount participate in transitions: if an uncaught
83
- * async read surfaces during the initial render (no `Loading` ancestor
84
- * absorbs it), the mount is held by the transition and attaches atomically
85
- * once all pending settles. On the no-async happy path the tail `flush()`
86
- * drains the queued callback so the attach is synchronous by the time
87
- * `render()` returns. The dev enforcement window scopes
88
- * `ASYNC_OUTSIDE_LOADING_BOUNDARY` to the initial mount only.
89
- */
90
- export declare function render(code: () => JSX.Element, element: MountableElement, init?: unknown, options?: {
91
- renderId?: string;
92
- }): () => void;
93
- /**
94
- * Resumes a server-rendered tree on the client, attaching event listeners
95
- * and reactive bindings without reconstructing the DOM. Returns a `dispose`
96
- * function that tears down reactive scopes (DOM nodes are left in place).
97
- *
98
- * Use this when the page HTML was produced by `renderToString`,
99
- * `renderToStringAsync`, or `renderToStream`. For client-only apps, use
100
- * `render` instead.
101
- *
102
- * Pass `options.renderId` to hydrate one of multiple roots emitted by a
103
- * server render that used the same id.
104
- *
105
- * @example
106
- * ```tsx
107
- * import { hydrate } from "@solidjs/web";
108
- *
109
- * hydrate(() => <App />, document.getElementById("root")!);
110
- * ```
111
- */
112
- export declare const hydrate: typeof hydrateCore;
113
- /**
114
- * Renders its children into a different part of the DOM (modal roots,
115
- * tooltips, layers that need to escape an `overflow: hidden` ancestor).
116
- *
117
- * If `mount` is omitted, the portal attaches to `document.body`. The portal
118
- * still participates in the parent's reactive scope and disposes when the
119
- * parent does.
120
- *
121
- * @example
122
- * ```tsx
123
- * <Portal mount={document.getElementById("modal-root")!}>
124
- * <Dialog />
125
- * </Portal>
126
- * ```
127
- *
128
- * @description https://docs.solidjs.com/reference/components/portal
129
- */
130
- export declare function Portal<T extends boolean = false, S extends boolean = false>(props: {
131
- mount?: Element;
132
- children: JSX.Element;
133
- }): JSX.Element;
134
- /**
135
- * Returns a stable `Component` whose identity is driven by a reactive (and
136
- * optionally async) `source`. The returned component can be used anywhere a
137
- * normal component is used; children and props flow through JSX as usual.
138
- *
139
- * `source` may return a component, a native tag name (`'input'`, `'textarea'`,
140
- * etc.), `undefined`, or a `Promise` of any of the above. A pending promise
141
- * propagates as `NotReadyError` through the surrounding reactive scope, so
142
- * async swaps compose with `<Loading>` boundaries the same way as `lazy`.
143
- *
144
- * @example
145
- * ```tsx
146
- * // `source` can return either a custom Component or a native tag
147
- * // name — they're interchangeable, and the returned reference is a
148
- * // stable Component you can use anywhere a normal one would go.
149
- * const Field = dynamic(() => multiline() ? RichTextEditor : "input");
150
- * return <Field value={value()} onInput={onInput} />;
151
- * ```
152
- *
153
- * @description https://docs.solidjs.com/reference/components/dynamic
154
- */
155
- export declare function dynamic<T extends ValidComponent>(source: () => T | Promise<T> | null | undefined | false): Component<ComponentProps<T>>;
156
- /**
157
- * Renders an arbitrary custom or native component and forwards the other
158
- * props. JSX form of `dynamic()` — same primitive, picked at the JSX site.
159
- *
160
- * @example
161
- * ```tsx
162
- * <Dynamic
163
- * component={multiline() ? RichTextEditor : "input"}
164
- * value={value()}
165
- * onInput={onInput}
166
- * />
167
- * ```
168
- *
169
- * @description https://docs.solidjs.com/reference/components/dynamic
170
- */
171
- export declare function Dynamic<T extends ValidComponent>(props: DynamicProps<T>): JSX.Element;
@@ -1,161 +0,0 @@
1
- /**
2
- * Renders a component tree synchronously to an HTML string. Async reads inside
3
- * `<Loading>` boundaries emit their `fallback` content; for full-graph
4
- * resolution use `renderToStringAsync` instead.
5
- *
6
- * Pair the returned HTML with `hydrate()` on the client.
7
- *
8
- * @example
9
- * ```tsx
10
- * import { renderToString } from "@solidjs/web";
11
- *
12
- * const html = renderToString(() => <App />);
13
- * res.send(`<!doctype html><html><body><div id="root">${html}</div></body></html>`);
14
- * ```
15
- */
16
- export declare function renderToString<T>(fn: () => T, options?: {
17
- nonce?: string;
18
- renderId?: string;
19
- noScripts?: boolean;
20
- plugins?: any[];
21
- manifest?: Record<string, {
22
- file: string;
23
- css?: string[];
24
- isEntry?: boolean;
25
- isDynamicEntry?: boolean;
26
- imports?: string[];
27
- }>;
28
- onError?: (err: any) => void;
29
- }): string;
30
- /**
31
- * Renders a component tree to an HTML string and awaits all async reads in the
32
- * subtree before resolving. The returned HTML reflects the fully-settled state
33
- * — no `<Loading>` fallbacks appear in the output.
34
- *
35
- * Use this when you want a complete page in one round-trip. For incremental
36
- * streaming with progressive boundary resolution, use `renderToStream`.
37
- *
38
- * @example
39
- * ```tsx
40
- * import { renderToStringAsync } from "@solidjs/web";
41
- *
42
- * const html = await renderToStringAsync(() => <App />);
43
- * ```
44
- */
45
- export declare function renderToStringAsync<T>(fn: () => T, options?: {
46
- timeoutMs?: number;
47
- nonce?: string;
48
- renderId?: string;
49
- noScripts?: boolean;
50
- plugins?: any[];
51
- manifest?: Record<string, {
52
- file: string;
53
- css?: string[];
54
- isEntry?: boolean;
55
- isDynamicEntry?: boolean;
56
- imports?: string[];
57
- }>;
58
- onError?: (err: any) => void;
59
- }): Promise<string>;
60
- /**
61
- * Streams an HTML response, flushing the synchronous shell first and then
62
- * progressively emitting async-resolved fragments as their `<Loading>`
63
- * boundaries settle. Good for time-to-first-byte sensitive pages.
64
- *
65
- * Returns an object with `pipe`/`pipeTo` for piping to a Node `Writable` or
66
- * a Web `WritableStream`, plus a `then` for awaiting full completion.
67
- *
68
- * @example
69
- * ```tsx
70
- * import { renderToStream } from "@solidjs/web";
71
- *
72
- * // Node:
73
- * renderToStream(() => <App />).pipe(res);
74
- *
75
- * // Web (Workers / Deno):
76
- * await renderToStream(() => <App />).pipeTo(stream.writable);
77
- * ```
78
- */
79
- export declare function renderToStream<T>(fn: () => T, options?: {
80
- nonce?: string;
81
- renderId?: string;
82
- noScripts?: boolean;
83
- plugins?: any[];
84
- manifest?: Record<string, {
85
- file: string;
86
- css?: string[];
87
- isEntry?: boolean;
88
- isDynamicEntry?: boolean;
89
- imports?: string[];
90
- }>;
91
- onCompleteShell?: (info: {
92
- write: (v: string) => void;
93
- }) => void;
94
- onCompleteAll?: (info: {
95
- write: (v: string) => void;
96
- }) => void;
97
- onError?: (err: any) => void;
98
- }): {
99
- then: (fn: (html: string) => void) => void;
100
- pipe: (writable: {
101
- write: (v: string) => void;
102
- end: () => void;
103
- }) => void;
104
- pipeTo: (writable: WritableStream) => Promise<void>;
105
- };
106
- /**
107
- * Compiler primitive — emitted by JSX-DOM-Expressions for tagged-template
108
- * SSR output. Not meant for hand-written code.
109
- * @internal
110
- */
111
- export declare function ssr(template: string[] | string, ...nodes: any[]): {
112
- t: string;
113
- };
114
- /**
115
- * Compiler primitive — emitted by JSX-DOM-Expressions for SSR element
116
- * output. Not meant for hand-written code.
117
- * @internal
118
- */
119
- export declare function ssrElement(name: string, props: any, children: any, needsId: boolean): {
120
- t: string;
121
- };
122
- /**
123
- * Compiler primitive — serializes a classList object for SSR output. Not
124
- * meant for hand-written code.
125
- * @internal
126
- */
127
- export declare function ssrClassList(value: {
128
- [k: string]: boolean;
129
- }): string;
130
- /**
131
- * Compiler primitive — serializes a style object for SSR output. Not meant
132
- * for hand-written code.
133
- * @internal
134
- */
135
- export declare function ssrStyle(value: {
136
- [k: string]: string;
137
- }): string;
138
- /**
139
- * Compiler primitive — serializes a boolean attribute for SSR output. Not
140
- * meant for hand-written code.
141
- * @internal
142
- */
143
- export declare function ssrAttribute(key: string, value: boolean): string;
144
- /**
145
- * Compiler primitive — generates the hydration-key attribute for SSR
146
- * output. Not meant for hand-written code.
147
- * @internal
148
- */
149
- export declare function ssrHydrationKey(): string;
150
- /**
151
- * Compiler primitive — collapses an SSR-shaped node into its HTML string.
152
- * Not meant for hand-written code.
153
- * @internal
154
- */
155
- export declare function resolveSSRNode(node: any): string;
156
- /**
157
- * Escapes a string for safe inclusion in HTML output. Used by the SSR
158
- * runtime; not generally part of user code.
159
- * @internal
160
- */
161
- export declare function escape(html: string): string;
@@ -1 +0,0 @@
1
- export * from "@dom-expressions/runtime/src/client.js";