solid-js 2.0.0-beta.1 → 2.0.0-beta.11

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 (38) hide show
  1. package/CHEATSHEET.md +640 -0
  2. package/README.md +42 -188
  3. package/dist/dev.cjs +446 -291
  4. package/dist/dev.js +426 -293
  5. package/dist/server.cjs +941 -345
  6. package/dist/server.js +897 -299
  7. package/dist/solid.cjs +438 -261
  8. package/dist/solid.js +418 -263
  9. package/package.json +67 -39
  10. package/types/client/component.d.ts +64 -19
  11. package/types/client/core.d.ts +110 -34
  12. package/types/client/flow.d.ts +176 -42
  13. package/types/client/hydration.d.ts +513 -37
  14. package/types/index.d.ts +8 -13
  15. package/types/server/component.d.ts +11 -11
  16. package/types/server/core.d.ts +19 -21
  17. package/types/server/flow.d.ts +76 -21
  18. package/types/server/hydration.d.ts +34 -9
  19. package/types/server/index.d.ts +6 -8
  20. package/types/server/shared.d.ts +10 -2
  21. package/types/server/signals.d.ts +80 -19
  22. package/types/types.d.ts +15 -0
  23. package/types-cjs/client/component.d.cts +120 -0
  24. package/types-cjs/client/core.d.cts +141 -0
  25. package/types-cjs/client/flow.d.cts +234 -0
  26. package/types-cjs/client/hydration.d.cts +568 -0
  27. package/types-cjs/index.d.cts +15 -0
  28. package/types-cjs/package.json +3 -0
  29. package/types-cjs/server/component.d.cts +67 -0
  30. package/types-cjs/server/core.d.cts +42 -0
  31. package/types-cjs/server/flow.d.cts +115 -0
  32. package/types-cjs/server/hydration.d.cts +63 -0
  33. package/types-cjs/server/index.d.cts +10 -0
  34. package/types-cjs/server/shared.d.cts +54 -0
  35. package/types-cjs/server/signals.d.cts +123 -0
  36. package/types-cjs/types.d.cts +15 -0
  37. package/jsx-runtime.d.ts +0 -1
  38. package/types/jsx.d.ts +0 -4129
@@ -0,0 +1,120 @@
1
+ import type { Element as SolidElement } from "../types.cjs";
2
+ /**
3
+ * A general `Component` has no implicit `children` prop. If desired, specify
4
+ * one explicitly, e.g. `Component<{ name: string; children: Element }>`.
5
+ */
6
+ export type Component<P extends Record<string, any> = {}> = (props: P) => SolidElement;
7
+ /**
8
+ * Extend props to forbid the `children` prop.
9
+ * Use this to prevent accidentally passing `children` to components that
10
+ * would silently throw them away.
11
+ */
12
+ export type VoidProps<P extends Record<string, any> = {}> = P & {
13
+ children?: never;
14
+ };
15
+ /**
16
+ * `VoidComponent` forbids the `children` prop.
17
+ * Use this to prevent accidentally passing `children` to components that
18
+ * would silently throw them away.
19
+ */
20
+ export type VoidComponent<P extends Record<string, any> = {}> = Component<VoidProps<P>>;
21
+ /**
22
+ * Extend props to allow optional Solid children.
23
+ * Use this for components that you want to accept children.
24
+ */
25
+ export type ParentProps<P extends Record<string, any> = {}> = P & {
26
+ children?: SolidElement;
27
+ };
28
+ /**
29
+ * `ParentComponent` allows an optional `children` prop.
30
+ * Use this for components that you want to accept children.
31
+ */
32
+ export type ParentComponent<P extends Record<string, any> = {}> = Component<ParentProps<P>>;
33
+ /**
34
+ * Extend props to require a `children` prop with the specified type.
35
+ * Use this for components where you need a specific child type,
36
+ * typically a function that receives specific argument types.
37
+ */
38
+ export type FlowProps<P extends Record<string, any> = {}, C = SolidElement> = P & {
39
+ children: C;
40
+ };
41
+ /**
42
+ * `FlowComponent` requires a `children` prop with the specified type.
43
+ * Use this for components where you need a specific child type,
44
+ * typically a function that receives specific argument types.
45
+ */
46
+ export type FlowComponent<P extends Record<string, any> = {}, C = SolidElement> = Component<FlowProps<P, C>>;
47
+ export type ValidComponent = Component<any>;
48
+ /**
49
+ * Takes the props of the passed component and returns its type
50
+ *
51
+ * Intrinsic element prop extraction is renderer-specific and lives in renderer
52
+ * packages such as `@solidjs/web`.
53
+ */
54
+ export type ComponentProps<T extends ValidComponent> = T extends Component<infer P> ? P : never;
55
+ /**
56
+ * Type of `props.ref`, for use in `Component` or `props` typing.
57
+ *
58
+ * @example Component<{ref: Ref<Element>}>
59
+ */
60
+ export type Ref<T> = T | ((val: T) => void);
61
+ /**
62
+ * Invokes a component, wrapping the call in `untrack` so that reactive reads
63
+ * inside the component body don't subscribe the parent computation. Compiled
64
+ * JSX uses this internally; manual calls are rarely needed unless authoring a
65
+ * custom JSX factory or renderer.
66
+ */
67
+ export declare function createComponent<T extends Record<string, any>>(Comp: Component<T>, props: T): SolidElement;
68
+ /**
69
+ * Defines a code-split component. The returned component triggers its dynamic
70
+ * import on first render and suspends through any enclosing `<Loading>`
71
+ * boundary while the chunk is in flight. Call `.preload()` to start the
72
+ * import early (e.g. on hover).
73
+ *
74
+ * @param fn dynamic import returning the module's default export
75
+ * @param moduleUrl optional module URL used during hydration to look up
76
+ * preloaded chunks; usually injected by the bundler integration
77
+ *
78
+ * @example
79
+ * ```tsx
80
+ * const Profile = lazy(() => import("./Profile"));
81
+ *
82
+ * function App() {
83
+ * return (
84
+ * <Loading fallback={<Spinner />}>
85
+ * <Profile id="42" />
86
+ * </Loading>
87
+ * );
88
+ * }
89
+ *
90
+ * // Preload before the user clicks
91
+ * <button onMouseEnter={() => Profile.preload()}>Open profile</button>
92
+ * ```
93
+ */
94
+ export declare function lazy<T extends Component<any>>(fn: () => Promise<{
95
+ default: T;
96
+ }>, moduleUrl?: string): T & {
97
+ preload: () => Promise<{
98
+ default: T;
99
+ }>;
100
+ moduleUrl?: string;
101
+ };
102
+ /**
103
+ * Returns a stable id string that matches between server-rendered and
104
+ * client-hydrated trees. Use it for `<label for>`, `aria-labelledby`, and
105
+ * other attributes that need consistent ids across SSR.
106
+ *
107
+ * @example
108
+ * ```tsx
109
+ * function Field(props: { label: string }) {
110
+ * const id = createUniqueId();
111
+ * return (
112
+ * <>
113
+ * <label for={id}>{props.label}</label>
114
+ * <input id={id} />
115
+ * </>
116
+ * );
117
+ * }
118
+ * ```
119
+ */
120
+ export declare function createUniqueId(): string;
@@ -0,0 +1,141 @@
1
+ import type { Accessor, EffectOptions } from "@solidjs/signals";
2
+ import type { ArrayElement, Element as SolidElement } from "../types.cjs";
3
+ import { FlowComponent } from "./component.cjs";
4
+ export declare const IS_DEV: string | boolean;
5
+ /**
6
+ * Brand symbol marking dev-built components for `solid-devtools` /
7
+ * AI-readiness instrumentation. Internal cross-package wiring.
8
+ *
9
+ * @internal
10
+ */
11
+ export declare const $DEVCOMP: unique symbol;
12
+ export type NoInfer<T extends any> = [T][T extends any ? 0 : never];
13
+ export type ContextProviderComponent<T> = FlowComponent<{
14
+ value: T;
15
+ }>;
16
+ export interface Context<T> extends ContextProviderComponent<T> {
17
+ id: symbol;
18
+ defaultValue: T | undefined;
19
+ }
20
+ /**
21
+ * Creates a Context for sharing state with descendants of a Provider in the
22
+ * component tree.
23
+ *
24
+ * The returned `Context` is itself a provider component — pass it a `value`
25
+ * prop to scope a value to its children. Read it inside descendants with
26
+ * `useContext`.
27
+ *
28
+ * Two forms:
29
+ *
30
+ * - **`createContext<T>()`** (default-less, the canonical form). Reading via
31
+ * `useContext` outside an enclosing Provider throws `ContextNotFoundError`.
32
+ * Use this for everything that carries reactive state — signals, stores,
33
+ * `[state, actions]` tuples, services. The Provider is mandatory by
34
+ * construction; the throw makes a missing Provider a loud bug instead of a
35
+ * silent no-op. The annotation `<T>` is required because there is no value
36
+ * to infer from.
37
+ * - **`createContext<T>(defaultValue)`** (default form). Reserved for the
38
+ * narrow case of contexts whose value is a primitive with a meaningful
39
+ * static fallback (theme, locale, frozen config). Outside any Provider,
40
+ * `useContext` returns `defaultValue`.
41
+ *
42
+ * If you want truly app-wide state, **don't use Context** — a module-scope
43
+ * signal/store *is* a global. Context is for scoping state to a subtree;
44
+ * that's why a Provider is required.
45
+ *
46
+ * @param defaultValue optional default; only meaningful for primitive
47
+ * fallbacks. Omit for any context carrying reactive state.
48
+ * @param options `{ name }` for debugging in development
49
+ * @returns a context object that doubles as its own provider component
50
+ *
51
+ * @example
52
+ * ```tsx
53
+ * // Reactive payload — default-less, throws if no Provider.
54
+ * type TodosCtx = readonly [Store<Todo[]>, TodoActions];
55
+ * const TodosContext = createContext<TodosCtx>();
56
+ *
57
+ * function App() {
58
+ * return (
59
+ * <TodosContext value={createTodos()}>
60
+ * <TodoList />
61
+ * </TodosContext>
62
+ * );
63
+ * }
64
+ *
65
+ * function TodoList() {
66
+ * const [todos, { addTodo }] = useContext(TodosContext); // typed as TodosCtx
67
+ * // ...
68
+ * }
69
+ * ```
70
+ *
71
+ * @example
72
+ * ```tsx
73
+ * // Primitive default — falls back to "light" outside a Provider.
74
+ * const ThemeContext = createContext<"light" | "dark">("light");
75
+ *
76
+ * function Button() {
77
+ * const theme = useContext(ThemeContext); // "light" | "dark"
78
+ * return <button class={theme}>Click</button>;
79
+ * }
80
+ * ```
81
+ *
82
+ * @description https://docs.solidjs.com/reference/component-apis/create-context
83
+ */
84
+ export declare function createContext<T>(defaultValue?: T, options?: EffectOptions): Context<T>;
85
+ /**
86
+ * Reads the current value of a context.
87
+ *
88
+ * - For `createContext<T>()` (default-less): returns the value from the
89
+ * nearest enclosing Provider, or throws `ContextNotFoundError` if none is
90
+ * mounted. Return type is `T` (no narrowing required).
91
+ * - For `createContext<T>(defaultValue)`: returns the value from the nearest
92
+ * enclosing Provider, or `defaultValue` if none is mounted.
93
+ *
94
+ * In Solid, `useContext` is the canonical way to read context. There is no
95
+ * need for a wrapper hook that throws on missing Provider — the default-less
96
+ * form already does that, and its return type is `T`.
97
+ *
98
+ * @param context a context returned from `createContext`
99
+ * @returns the value provided by the nearest enclosing Provider, or the
100
+ * default if one was supplied to `createContext`
101
+ * @throws `ContextNotFoundError` if no Provider is mounted and the context
102
+ * was created without a default
103
+ *
104
+ * @example
105
+ * ```tsx
106
+ * const TodosContext = createContext<TodosCtx>();
107
+ *
108
+ * function TodoList() {
109
+ * const [todos, { addTodo }] = useContext(TodosContext); // throws if no Provider
110
+ * // ...
111
+ * }
112
+ * ```
113
+ *
114
+ * @description https://docs.solidjs.com/reference/component-apis/use-context
115
+ */
116
+ export declare function useContext<T>(context: Context<T>): T;
117
+ export type ResolvedElement = Exclude<SolidElement, ArrayElement>;
118
+ export type ResolvedChildren = ResolvedElement | ResolvedElement[];
119
+ export type ChildrenReturn = Accessor<ResolvedChildren> & {
120
+ toArray: () => ResolvedElement[];
121
+ };
122
+ /**
123
+ * Resolves a `children` accessor and exposes the result as an accessor with
124
+ * a `.toArray()` helper. Use this when a component needs to inspect or
125
+ * iterate over its children rather than just render them through.
126
+ *
127
+ * @param fn an accessor for the children
128
+ * @returns an accessor of the resolved children, with `.toArray()` for iteration
129
+ *
130
+ * @example
131
+ * ```tsx
132
+ * function List(props: { children: Element }) {
133
+ * const items = children(() => props.children);
134
+ * return <ul>{items.toArray().map(item => <li>{item}</li>)}</ul>;
135
+ * }
136
+ * ```
137
+ *
138
+ * @description https://docs.solidjs.com/reference/component-apis/children
139
+ */
140
+ export declare function children(fn: Accessor<SolidElement>): ChildrenReturn;
141
+ export declare function devComponent<P, V>(Comp: (props: P) => V, props: P): V;
@@ -0,0 +1,234 @@
1
+ import type { Accessor, RevealOrder } from "@solidjs/signals";
2
+ export type { RevealOrder };
3
+ import type { Element as SolidElement } from "../types.cjs";
4
+ type NonZeroParams<T extends (...args: any[]) => any> = Parameters<T>["length"] extends 0 ? never : T;
5
+ type ConditionalRenderCallback<T> = (item: Accessor<NonNullable<T>>) => SolidElement;
6
+ type ConditionalRenderChildren<T, F extends ConditionalRenderCallback<T> = ConditionalRenderCallback<T>> = SolidElement | NonZeroParams<F>;
7
+ /**
8
+ * Creates a list of elements from a list.
9
+ *
10
+ * Receives a map function as its child that takes list element and index
11
+ * accessors and returns a JSX element; if the list is empty, an optional
12
+ * `fallback` is rendered instead.
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * <For each={items} fallback={<div>No items</div>}>
17
+ * {(item, index) => <div data-index={index()}>{item()}</div>}
18
+ * </For>
19
+ * ```
20
+ *
21
+ * @description https://docs.solidjs.com/reference/components/for
22
+ */
23
+ export declare function For<T extends readonly any[], U extends SolidElement>(props: {
24
+ each: T | undefined | null | false;
25
+ fallback?: SolidElement;
26
+ keyed?: boolean | ((item: T[number]) => any);
27
+ children: (item: Accessor<T[number]>, index: Accessor<number>) => U;
28
+ }): SolidElement;
29
+ /**
30
+ * Creates a list of elements from a count.
31
+ *
32
+ * Receives a map function as its child that takes the index and returns a JSX
33
+ * element; if the count is zero, an optional `fallback` is rendered instead.
34
+ *
35
+ * @example
36
+ * ```tsx
37
+ * <Repeat count={items.length} fallback={<div>No items</div>}>
38
+ * {(index) => <div data-index={index}>{items[index]}</div>}
39
+ * </Repeat>
40
+ * ```
41
+ *
42
+ * @description https://docs.solidjs.com/reference/components/repeat
43
+ */
44
+ export declare function Repeat<T extends SolidElement>(props: {
45
+ count: number;
46
+ from?: number | undefined;
47
+ fallback?: SolidElement;
48
+ children: ((index: number) => T) | T;
49
+ }): SolidElement;
50
+ /**
51
+ * Conditionally renders its children when `when` is truthy, otherwise renders
52
+ * the optional `fallback`.
53
+ *
54
+ * The function-child form receives an accessor for the narrowed value — call
55
+ * it to read. Without `keyed` (default), the child is preserved across
56
+ * truthy values; with `keyed`, the child remounts whenever the value's
57
+ * identity changes.
58
+ *
59
+ * @example
60
+ * ```tsx
61
+ * <Show when={user()} fallback={<SignIn />}>
62
+ * {u => <Greeting name={u().name} />}
63
+ * </Show>
64
+ * ```
65
+ *
66
+ * @description https://docs.solidjs.com/reference/components/show
67
+ */
68
+ export declare function Show<T, F extends ConditionalRenderCallback<T>>(props: {
69
+ when: T | undefined | null | false;
70
+ keyed?: boolean;
71
+ fallback?: SolidElement;
72
+ children: ConditionalRenderChildren<T, F>;
73
+ }): SolidElement;
74
+ /**
75
+ * Switches between content based on mutually exclusive conditions. Renders
76
+ * the first `<Match>` whose `when` is truthy; falls back to `fallback` when
77
+ * none match.
78
+ *
79
+ * @example
80
+ * ```tsx
81
+ * <Switch fallback={<FourOhFour />}>
82
+ * <Match when={state.route === 'home'}>
83
+ * <Home />
84
+ * </Match>
85
+ * <Match when={state.route === 'settings'}>
86
+ * <Settings />
87
+ * </Match>
88
+ * </Switch>
89
+ * ```
90
+ *
91
+ * @description https://docs.solidjs.com/reference/components/switch-and-match
92
+ */
93
+ export declare function Switch(props: {
94
+ fallback?: SolidElement;
95
+ children: SolidElement;
96
+ }): SolidElement;
97
+ export type MatchProps<T, F extends ConditionalRenderCallback<T> = ConditionalRenderCallback<T>> = {
98
+ when: T | undefined | null | false;
99
+ keyed?: boolean;
100
+ children: ConditionalRenderChildren<T, F>;
101
+ };
102
+ /**
103
+ * A branch inside a `<Switch>`. The first `<Match>` whose `when` is truthy
104
+ * wins; remaining matches are skipped.
105
+ *
106
+ * Like `<Show>`, `<Match>` supports a function child that receives an
107
+ * accessor for the narrowed value.
108
+ *
109
+ * @example
110
+ * ```tsx
111
+ * <Switch fallback={<NotFound />}>
112
+ * <Match when={user()}>
113
+ * {u => <Profile name={u().name} />}
114
+ * </Match>
115
+ * <Match when={loading()}>
116
+ * <Spinner />
117
+ * </Match>
118
+ * </Switch>
119
+ * ```
120
+ *
121
+ * @description https://docs.solidjs.com/reference/components/switch-and-match
122
+ */
123
+ export declare function Match<T, F extends ConditionalRenderCallback<T>>(props: MatchProps<T, F>): SolidElement;
124
+ /**
125
+ * Catches uncaught errors inside its subtree and renders fallback content
126
+ * instead. The `fallback` prop can be a JSX element, or a callback that
127
+ * receives the error and a `reset()` function for retry affordances.
128
+ *
129
+ * Errors thrown from the fallback itself can be caught by a parent
130
+ * `<Errored>`.
131
+ *
132
+ * @example
133
+ * ```tsx
134
+ * <Errored fallback={(err, reset) => (
135
+ * <div onClick={reset}>Error: {err.toString()}</div>
136
+ * )}>
137
+ * <MyComp />
138
+ * </Errored>
139
+ * ```
140
+ *
141
+ * @description https://docs.solidjs.com/reference/components/error-boundary
142
+ */
143
+ export declare function Errored(props: {
144
+ fallback: SolidElement | ((err: any, reset: () => void) => SolidElement);
145
+ children: SolidElement;
146
+ }): SolidElement;
147
+ /**
148
+ * Renders a `fallback` while pending async reads inside the subtree settle.
149
+ *
150
+ * Any computation (`createMemo`, `createSignal(fn)`, `createStore(fn)`,
151
+ * `lazy(...)`, etc.) that throws because data isn't ready is caught by the
152
+ * nearest enclosing `<Loading>`. The boundary swaps to its `fallback` until
153
+ * every pending read has resolved, then renders the children.
154
+ *
155
+ * The optional `on` prop scopes the boundary so it ignores transitions
156
+ * caused by writes to other reactive sources — those transitions stay on the
157
+ * previous content (with `isPending()` flipping during the transition).
158
+ *
159
+ * Scope `<Loading>` around the data-dependent slot, not the surrounding
160
+ * shell. Wrapping layout chrome (header, nav, footer) in the same boundary
161
+ * as the data means revalidation replaces the entire screen with the
162
+ * fallback; rendering chrome outside the boundary keeps it stable while
163
+ * only the affordance flips.
164
+ *
165
+ * @example
166
+ * ```tsx
167
+ * const Profile = lazy(() => import("./Profile"));
168
+ *
169
+ * <Loading fallback={<Spinner />}>
170
+ * <Profile />
171
+ * </Loading>
172
+ * ```
173
+ *
174
+ * @example
175
+ * ```tsx
176
+ * // Only show the fallback for transitions caused by writes to `route`.
177
+ * <Loading fallback={<Skeleton />} on={route}>
178
+ * <Page />
179
+ * </Loading>
180
+ * ```
181
+ *
182
+ * @description https://docs.solidjs.com/reference/components/suspense
183
+ */
184
+ export declare function Loading(props: {
185
+ fallback?: SolidElement;
186
+ on?: any;
187
+ children: SolidElement;
188
+ }): SolidElement;
189
+ export type RevealProps = {
190
+ order?: RevealOrder;
191
+ collapsed?: boolean;
192
+ children: SolidElement;
193
+ };
194
+ /**
195
+ * Coordinates the reveal timing of sibling `<Loading>` boundaries.
196
+ *
197
+ * The `order` prop picks the reveal policy:
198
+ * - `"sequential"` (default) — boundaries reveal in registration order; later boundaries
199
+ * stay on their fallback until earlier ones resolve.
200
+ * - `"together"` — every direct slot stays on its fallback until the whole group is
201
+ * "minimally ready" (every direct slot has its own first visible content available),
202
+ * then the group releases in one cohesive reveal.
203
+ * - `"natural"` — each boundary reveals as its own data resolves. At the top level
204
+ * this is equivalent to omitting `<Reveal>`; the mode exists for nesting, where
205
+ * the group registers as a single composite slot in an enclosing `<Reveal>`.
206
+ *
207
+ * The `collapsed` prop is only consulted when `order="sequential"` (the default);
208
+ * it is ignored under `"together"` and `"natural"`. When set, tail boundaries past
209
+ * the frontier suppress their own fallback output.
210
+ *
211
+ * Nested `<Reveal>` groups compose: the inner group is one slot in the outer order
212
+ * and is held on its fallbacks until the outer releases the slot. Once released, the
213
+ * inner group runs its own `order` locally over whatever is still pending. There is
214
+ * no escape hatch — nesting under an outer group means participating in its ordering.
215
+ * See `documentation/solid-2.0/03-control-flow.md` for the full nesting matrix and the
216
+ * "minimally ready" definition per order.
217
+ *
218
+ * @example
219
+ * ```tsx
220
+ * // Default order is "sequential"; the inner group composes as one slot
221
+ * // and runs its own "natural" order locally once the outer releases it.
222
+ * <Reveal>
223
+ * <Loading fallback={<Skeleton />}><ProfileHeader /></Loading>
224
+ * <Reveal order="natural">
225
+ * <Loading fallback={<Skeleton />}><PostA /></Loading>
226
+ * <Loading fallback={<Skeleton />}><PostB /></Loading>
227
+ * </Reveal>
228
+ * <Loading fallback={<Skeleton />}><Comments /></Loading>
229
+ * </Reveal>
230
+ * ```
231
+ *
232
+ * @description https://docs.solidjs.com/reference/components/reveal
233
+ */
234
+ export declare function Reveal(props: RevealProps): SolidElement;