@solidjs/web 2.0.0-experimental.9 → 2.0.0-rc.0

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.
Files changed (85) hide show
  1. package/README.md +22 -4
  2. package/dist/dev.cjs +1585 -225
  3. package/dist/dev.js +1510 -201
  4. package/dist/server.cjs +2642 -264
  5. package/dist/server.js +2542 -217
  6. package/dist/web.cjs +1523 -218
  7. package/dist/web.js +1448 -194
  8. package/frames/dist/client.cjs +1916 -0
  9. package/frames/dist/client.dev.cjs +1933 -0
  10. package/frames/dist/client.dev.js +1921 -0
  11. package/frames/dist/client.js +1904 -0
  12. package/frames/dist/server.cjs +3667 -0
  13. package/frames/dist/server.js +3654 -0
  14. package/frames/package.json +30 -0
  15. package/package.json +349 -37
  16. package/serialization/decode/package.json +20 -0
  17. package/serialization/dist/decode.cjs +110 -0
  18. package/serialization/dist/decode.js +104 -0
  19. package/serialization/dist/serialization.cjs +232 -0
  20. package/serialization/dist/serialization.js +215 -0
  21. package/serialization/package.json +20 -0
  22. package/serialization/types/index.d.ts +182 -0
  23. package/serialization/types/serializer-decode.d.ts +182 -0
  24. package/serialization/types-cjs/index.d.cts +182 -0
  25. package/serialization/types-cjs/package.json +3 -0
  26. package/serialization/types-cjs/serializer-decode.d.cts +182 -0
  27. package/server-functions/dist/client.cjs +646 -0
  28. package/server-functions/dist/client.js +617 -0
  29. package/server-functions/dist/rich-args.cjs +11 -0
  30. package/server-functions/dist/rich-args.js +9 -0
  31. package/server-functions/dist/server.cjs +1077 -0
  32. package/server-functions/dist/server.dev.cjs +1077 -0
  33. package/server-functions/dist/server.dev.js +1045 -0
  34. package/server-functions/dist/server.js +1045 -0
  35. package/server-functions/package.json +40 -0
  36. package/server-functions/rich-args/package.json +20 -0
  37. package/storage/package.json +8 -3
  38. package/storage/types/index.d.ts +26 -0
  39. package/storage/types-cjs/index.d.cts +28 -0
  40. package/storage/types-cjs/package.json +3 -0
  41. package/types/client.d.ts +290 -27
  42. package/types/cookies.d.ts +93 -0
  43. package/types/core.d.ts +6 -2
  44. package/types/frames/client.d.ts +36 -0
  45. package/types/frames/frame-client.d.ts +338 -0
  46. package/types/frames/frame-sink.d.ts +194 -0
  47. package/types/frames/frame-transport.d.ts +222 -0
  48. package/types/frames/serializer.d.ts +182 -0
  49. package/types/frames/server.d.ts +52 -0
  50. package/types/index.d.ts +209 -24
  51. package/types/jsx-properties.d.ts +93 -0
  52. package/types/jsx.d.ts +4150 -1
  53. package/types/response.d.ts +174 -0
  54. package/types/serializer-decode.d.ts +182 -0
  55. package/types/serializer.d.ts +182 -0
  56. package/types/server-functions/client.d.ts +201 -0
  57. package/types/server-functions/flash.d.ts +38 -0
  58. package/types/server-functions/rich-args.d.ts +10 -0
  59. package/types/server-functions/server.d.ts +588 -0
  60. package/types/server-functions/shared.d.ts +523 -0
  61. package/types/server-mock.d.ts +249 -12
  62. package/types/server.d.ts +424 -51
  63. package/types-cjs/client.d.cts +337 -0
  64. package/types-cjs/cookies.d.cts +93 -0
  65. package/types-cjs/core.d.cts +6 -0
  66. package/types-cjs/frames/client.d.cts +36 -0
  67. package/types-cjs/frames/frame-client.d.cts +338 -0
  68. package/types-cjs/frames/frame-sink.d.cts +194 -0
  69. package/types-cjs/frames/frame-transport.d.cts +222 -0
  70. package/types-cjs/frames/serializer.d.cts +182 -0
  71. package/types-cjs/frames/server.d.cts +52 -0
  72. package/types-cjs/index.d.cts +230 -0
  73. package/types-cjs/jsx-properties.d.cts +93 -0
  74. package/types-cjs/jsx.d.cts +4150 -0
  75. package/types-cjs/package.json +3 -0
  76. package/types-cjs/response.d.cts +174 -0
  77. package/types-cjs/serializer-decode.d.cts +182 -0
  78. package/types-cjs/serializer.d.cts +182 -0
  79. package/types-cjs/server-functions/client.d.cts +201 -0
  80. package/types-cjs/server-functions/flash.d.cts +38 -0
  81. package/types-cjs/server-functions/rich-args.d.cts +10 -0
  82. package/types-cjs/server-functions/server.d.cts +588 -0
  83. package/types-cjs/server-functions/shared.d.cts +523 -0
  84. package/types-cjs/server-mock.d.cts +277 -0
  85. package/types-cjs/server.d.cts +523 -0
package/types/index.d.ts CHANGED
@@ -1,45 +1,230 @@
1
1
  import { hydrate as hydrateCore } from "./client.js";
2
- import { JSX, ComponentProps, ValidComponent } from "solid-js";
2
+ import { Component } from "solid-js";
3
+ import type { JSX } from "./jsx.js";
3
4
  export * from "./client.js";
4
- export { For, Show, Suspense, Switch, Match, ErrorBoundary, merge as mergeProps } from "solid-js";
5
5
  export * from "./server-mock.js";
6
+ export * from "./response.js";
7
+ export type { JSX } from "./jsx.js";
8
+ export { For, Show, Switch, Match, Errored, Loading, Repeat, Reveal, NoHydration, Hydration } from "solid-js";
9
+ import { merge } from "solid-js";
10
+ /**
11
+ * Compiler-emitted prop-spread helper. The JSX transform (in
12
+ * `dom-expressions`) emits `mergeProps(...)` calls when compiling prop
13
+ * spreads on components — it is *not* a user-facing API. Application code
14
+ * should import `merge` from `solid-js` directly.
15
+ *
16
+ * @internal
17
+ */
18
+ export declare const mergeProps: typeof merge;
19
+ /**
20
+ * Build-time constant indicating whether code is running on the server. This
21
+ * client entry sets it to `false`; the matching server entry (`@solidjs/web`
22
+ * resolved through the `solid` server export condition) sets it to `true`.
23
+ *
24
+ * Bundlers can dead-code-eliminate branches gated on `isServer`, so guarding
25
+ * browser-only code with `if (!isServer) {…}` keeps it out of the SSR bundle
26
+ * entirely.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import { isServer } from "@solidjs/web";
31
+ *
32
+ * if (!isServer) {
33
+ * // Browser-only: tree-shaken out of the SSR bundle.
34
+ * window.addEventListener("resize", onResize);
35
+ * }
36
+ * ```
37
+ */
6
38
  export declare const isServer: boolean;
7
- export declare const isDev: boolean;
8
- export declare const hydrate: typeof hydrateCore;
9
39
  /**
10
- * Renders components somewhere else in the DOM
40
+ * Build-time constant indicating whether code is running in a dev build.
41
+ * Replaced statically (`_SOLID_DEV_`) by the bundler integration, so guards
42
+ * like `if (isDev) {…}` are stripped from production builds.
11
43
  *
12
- * Useful for inserting modals and tooltips outside of an cropping layout. If no mount point is given, the portal is inserted in document.body; it is wrapped in a `<div>` unless the target is document.head or `isSVG` is true. setting `useShadow` to true places the element in a shadow root to isolate styles.
44
+ * Use this to gate dev-only diagnostics, warnings, or expensive invariants
45
+ * that should never ship to production.
13
46
  *
14
- * @description https://docs.solidjs.com/reference/components/portal
47
+ * @example
48
+ * ```ts
49
+ * import { isDev } from "@solidjs/web";
50
+ *
51
+ * if (isDev) {
52
+ * console.warn("debug-only path");
53
+ * }
54
+ * ```
15
55
  */
16
- export declare function Portal<T extends boolean = false, S extends boolean = false>(props: {
17
- mount?: Element;
18
- children: JSX.Element;
19
- }): Text;
56
+ export declare const isDev: boolean;
57
+ type MountableElement = Element | Document | ShadowRoot | DocumentFragment | Node;
58
+ export type IntrinsicElement = Extract<keyof JSX.IntrinsicElements, string>;
59
+ export type ValidComponent = IntrinsicElement | Component<any> | (string & {});
60
+ export type ComponentProps<T extends ValidComponent> = T extends Component<infer P> ? P : T extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[T] : Record<string, unknown>;
20
61
  export type DynamicProps<T extends ValidComponent, P = ComponentProps<T>> = {
21
62
  [K in keyof P]: P[K];
22
63
  } & {
23
- component: T | undefined;
64
+ component: T | null | undefined | false;
24
65
  };
25
66
  /**
26
- * Renders an arbitrary component or element with the given props
67
+ * Renders a component tree into a DOM element. Returns a dispose function
68
+ * that tears the tree down and cleans up reactive scopes when called.
69
+ *
70
+ * @example
71
+ * ```tsx
72
+ * import { render } from "@solidjs/web";
27
73
  *
28
- * This is a lower level version of the `Dynamic` component, useful for
29
- * performance optimizations in libraries. Do not use this unless you know
30
- * what you are doing.
31
- * ```typescript
32
- * const element = () => multiline() ? 'textarea' : 'input';
33
- * createDynamic(element, { value: value() });
74
+ * const dispose = render(() => <App />, document.getElementById("root")!);
75
+ *
76
+ * // Later, to unmount:
77
+ * dispose();
34
78
  * ```
35
- * @description https://docs.solidjs.com/reference/components/dynamic
79
+ *
80
+ * @remarks
81
+ * The top-level insert is queued via `insertOptions: { schedule: true }` so
82
+ * its initial DOM attach goes through the effect queue rather than executing
83
+ * inline. This lets the mount participate in transitions: if an uncaught
84
+ * async read surfaces during the initial render (no `Loading` ancestor
85
+ * absorbs it), the mount is held by the transition and attaches atomically
86
+ * once all pending settles. On the no-async happy path the tail `flush()`
87
+ * drains the queued callback so the attach is synchronous by the time
88
+ * `render()` returns. The dev enforcement window scopes
89
+ * `ASYNC_OUTSIDE_LOADING_BOUNDARY` to the initial mount only.
36
90
  */
37
- export declare function createDynamic<T extends ValidComponent>(component: () => T | undefined, props: ComponentProps<T>): JSX.Element;
91
+ export declare function render(code: () => JSX.Element, element: MountableElement, init?: unknown, options?: {
92
+ renderId?: string;
93
+ }): () => void;
38
94
  /**
39
- * Renders an arbitrary custom or native component and passes the other props
40
- * ```typescript
41
- * <Dynamic component={multiline() ? 'textarea' : 'input'} value={value()} />
95
+ * Resumes a server-rendered tree on the client, attaching event listeners
96
+ * and reactive bindings without reconstructing the DOM. Returns a `dispose`
97
+ * function that tears down reactive scopes (DOM nodes are left in place).
98
+ *
99
+ * Use this when the page HTML was produced by `renderToString` or
100
+ * `renderToStream`. For client-only apps, use `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")!);
42
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
+ * 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
+ *
127
+ * @example
128
+ * ```tsx
129
+ * <Portal mount={document.getElementById("modal-root")!}>
130
+ * <Dialog />
131
+ * </Portal>
132
+ * ```
133
+ *
134
+ * @description https://docs.solidjs.com/reference/components/portal
135
+ */
136
+ export declare function Portal(props: {
137
+ mount?: Element;
138
+ children: JSX.Element;
139
+ }): JSX.Element;
140
+ export declare function dynamic<T extends ValidComponent>(source: () => T | Promise<T> | null | undefined | false): Component<ComponentProps<T>>;
141
+ /**
142
+ * Renders an arbitrary custom or native component and forwards the other
143
+ * props. JSX form of `dynamic()` — same primitive, picked at the JSX site.
144
+ *
145
+ * @example
146
+ * ```tsx
147
+ * <Dynamic
148
+ * component={multiline() ? RichTextEditor : "input"}
149
+ * value={value()}
150
+ * onInput={onInput}
151
+ * />
152
+ * ```
153
+ *
43
154
  * @description https://docs.solidjs.com/reference/components/dynamic
44
155
  */
45
156
  export declare function Dynamic<T extends ValidComponent>(props: DynamicProps<T>): JSX.Element;
157
+ /**
158
+ * Wraps a dynamically imported component so it renders only in the browser.
159
+ * The server renders `props.fallback` (and nothing else); the client shows
160
+ * the fallback until the import resolves and the tree has mounted, then
161
+ * swaps the real component in.
162
+ *
163
+ * Unlike `lazy()`, this avoids Suspense entirely and never server-renders
164
+ * the wrapped component — only the fallback — so the component participates
165
+ * in no hydration asset manifest and its code is guaranteed to never run on
166
+ * the server (safe for browser-only libraries touching `window`, DOM
167
+ * measurement, etc.). The mount gate keeps hydration safe: during hydration
168
+ * the fallback is rendered exactly as the server did, and the swap happens
169
+ * only after settle, so there is no mismatch.
170
+ *
171
+ * By default the import starts as soon as `clientOnly` is called (module
172
+ * load); pass `{ lazy: true }` to defer the import to the component's first
173
+ * render.
174
+ *
175
+ * @example
176
+ * ```tsx
177
+ * const Chart = clientOnly(() => import("./Chart.jsx"));
178
+ * // <Chart fallback={<div>Loading chart…</div>} data={data()} />
179
+ * ```
180
+ */
181
+ export declare function clientOnly<T extends Component<any>>(fn: () => Promise<{
182
+ default: T;
183
+ }>, options?: {
184
+ lazy?: boolean;
185
+ }, _moduleUrl?: string): Component<ComponentProps<T> & {
186
+ fallback?: JSX.Element;
187
+ }>;
188
+ /**
189
+ * Declares the HTTP response status (and optional status text) for the
190
+ * lifetime of the current reactive scope during SSR — call it bare in a
191
+ * component or reactive-scope body where the status is decided (a 404
192
+ * route, an error fallback). Client build: a no-op — the response head was
193
+ * sent long ago.
194
+ *
195
+ * Naming note — this is a scope-tied *declaration*, not a mutation: "while
196
+ * this reactive scope is live, the response has this status." Solid
197
+ * reserves `set*` verbs for event-time mutation; like
198
+ * `createSignal`/`onCleanup` this is called in scope bodies and un-declares
199
+ * on scope disposal.
200
+ *
201
+ * Retraction semantics (server): the write snapshots the previous
202
+ * `event.response` status at write time and restores it when the owning
203
+ * scope is disposed — so a boundary that errored, declared a status, and
204
+ * then recovered retracts its write instead of stomping a status a
205
+ * surviving part of the tree legitimately set. Once the integration marks
206
+ * the response head `committed` (head derived/sent), writes and
207
+ * retractions are no-ops.
208
+ */
209
+ export declare function httpStatus(_code: number, _text?: string): void;
210
+ /**
211
+ * Declares an HTTP response header (or with `append`, appends to one) for
212
+ * the lifetime of the current reactive scope during SSR — call it bare in a
213
+ * component or reactive-scope body. Client build: a no-op — the response
214
+ * head was sent long ago.
215
+ *
216
+ * Naming note — this is a scope-tied *declaration*, not a mutation: "while
217
+ * this reactive scope is live, the response has this header." Solid
218
+ * reserves `set*` verbs for event-time mutation; like
219
+ * `createSignal`/`onCleanup` this is called in scope bodies and un-declares
220
+ * on scope disposal.
221
+ *
222
+ * Retraction semantics (server): the header's prior value is snapshotted at
223
+ * write time and restored when the owning scope is disposed (deleted if
224
+ * there was none) — a boundary that errors or recovers retracts its writes.
225
+ * Once the integration marks the response head `committed` (head
226
+ * derived/sent), writes and retractions are no-ops.
227
+ */
228
+ export declare function httpHeader(_name: string, _value: string, _options?: {
229
+ append?: boolean;
230
+ }): void;
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Shared type-level helpers used to derive `prop:*` attribute typings from
3
+ * DOM element interfaces (e.g. `HTMLInputElement`, `HTMLButtonElement`).
4
+ *
5
+ * The wrapping of each value (`FunctionMaybe<T>` in `jsx-h.d.ts` vs. the
6
+ * raw value in `jsx.d.ts`) is applied by each consumer when composing its
7
+ * own `Properties<T>` mapped type. That way this file stays identical in
8
+ * both reactive and non-reactive contexts and only needs to exist once.
9
+ *
10
+ * originally from
11
+ * @url https://github.com/potahtml/pota
12
+ */
13
+
14
+ /** Base-class properties shared by all elements — skipped from `prop:*`. */
15
+ export type SkipPropsFrom = HTMLUnknownElement & HTMLElement & Element & Node;
16
+
17
+ /**
18
+ * Value types allowed on a `prop:*`. Primitives plus the writable
19
+ * non-primitive DOM-object props worth exposing:
20
+ *
21
+ * - `HTMLMediaElement.srcObject`
22
+ * - `HTMLButtonElement.popoverTargetElement` / `commandForElement` (and the same via
23
+ * `PopoverTargetAttributes` mixin on `HTMLInputElement`)
24
+ */
25
+ export type PropValue =
26
+ | string
27
+ | number
28
+ | boolean
29
+ | null
30
+ | MediaStream
31
+ | MediaSource
32
+ | Blob
33
+ | File
34
+ | Date
35
+ | Element;
36
+
37
+ /**
38
+ * Ergonomics widening for emitted `prop:*` value types:
39
+ *
40
+ * - general `string` → `string | number` (HTML coerces numbers)
41
+ * - string literal unions (`'on' | 'off'`) stay exact, so users still get autocomplete /
42
+ * narrowing
43
+ * - other types pass through unchanged
44
+ */
45
+ type WidenString<V> = string extends V ? string | number : V;
46
+ export type WidenPropValue<V> = [V] extends [string] ? WidenString<V> : V;
47
+
48
+ /**
49
+ * Structurally identical → `Y`; distinct → `N`. Used by `IsReadonlyKey` to detect
50
+ * readonly keys by comparing `Pick<T, K>` with `Readonly<Pick<T, K>>`.
51
+ */
52
+ export type IfEquals<A, B, Y = unknown, N = never> =
53
+ (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? Y : N;
54
+
55
+ /**
56
+ * True when `K` is readonly on `T`. Singleton-constant properties (e.g.
57
+ * `tagName: "INPUT"`, `nodeType: 1`) are always `readonly` in `lib.dom.d.ts`, so this
58
+ * single check covers both readonly and singleton-literal cases.
59
+ */
60
+ export type IsReadonlyKey<T, K extends keyof T> = IfEquals<
61
+ Pick<T, K>,
62
+ Readonly<Pick<T, K>>,
63
+ true,
64
+ false
65
+ >;
66
+
67
+ /**
68
+ * Resolves to the `prop:K` string literal when `K` is a writable, element-specific
69
+ * property suitable for a `prop:*` attribute; otherwise resolves to `never` so the
70
+ * key is filtered out of the resulting mapped type.
71
+ *
72
+ * Filters out:
73
+ *
74
+ * - base-class keys (via `SkipPropsFrom`)
75
+ * - aria-* keys (already typed via `AriaAttributes`)
76
+ * - readonly keys
77
+ * - keys whose value types fall outside `PropValue`
78
+ * - the generic `string` index signature (e.g. `HTMLFormElement[name: string]: any`),
79
+ * which would otherwise shadow every key with an `any`-typed `prop:*`
80
+ */
81
+ export type PropKey<T, K extends keyof T> = K extends keyof SkipPropsFrom
82
+ ? never
83
+ : K extends string
84
+ ? string extends K
85
+ ? never
86
+ : K extends `aria${string}`
87
+ ? never
88
+ : T[K] extends PropValue
89
+ ? IsReadonlyKey<T, K> extends true
90
+ ? never
91
+ : `prop:${K}`
92
+ : never
93
+ : never;