Skip to content

Commit 1e410e6

Browse files
committed
update docs for accuracy
1 parent e0f4812 commit 1e410e6

5 files changed

Lines changed: 83 additions & 61 deletions

File tree

public/llms.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
- [<Suspense>](https://docs.solidjs.com/reference/components/suspense)
7272
- [<SuspenseList>](https://docs.solidjs.com/reference/components/suspense-list)
7373
- [<Switch> / <Match>](https://docs.solidjs.com/reference/components/switch-and-match)
74+
- [createDynamic](https://docs.solidjs.com/reference/components/create-dynamic)
7475
- [@once](https://docs.solidjs.com/reference/jsx-attributes/once)
7576
- [attr:*](https://docs.solidjs.com/reference/jsx-attributes/attr)
7677
- [bool:*](https://docs.solidjs.com/reference/jsx-attributes/bool)

src/routes/reference/component-apis/create-unique-id.mdx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ tags:
1111
- utilities
1212
version: "1.0"
1313
description: >-
14-
Generate unique IDs that are stable across server and client with
15-
createUniqueId. Essential for accessible forms and SSR-compatible components.
14+
Generate a unique string for the current render or hydration context.
1615
---
1716

18-
The `createUniqueId` function generates a unique ID that remains consistent across both server and client renders.
19-
It is commonly used with HTML `id` and `for` attributes to ensure stable hydration.
17+
`createUniqueId` generates a unique string for the current render or hydration context.
18+
During hydration, matching server and client call order produces matching IDs.
2019

2120
`createUniqueId` does _not_ generate a cryptographically secure ID and is not suitable for security-sensitive data.
2221
Additionally, it should not be used in scenarios that require uniqueness across a distributed system.
@@ -48,6 +47,11 @@ This function does not take any parameters.
4847

4948
`createUniqueId` returns a unique `string` that is stable across server and client renders.
5049

50+
## Behavior
51+
52+
- During hydration, IDs come from the current hydration context, so matching call order produces matching server and client IDs.
53+
- Outside hydration context, client-side IDs use a local counter and are unique only within the current Solid runtime instance.
54+
5155
## Examples
5256

5357
### Basic Usage
@@ -57,9 +61,17 @@ import { createUniqueId } from "solid-js";
5761

5862
type InputProps = {
5963
id?: string;
64+
label: string;
6065
};
6166

6267
function Input(props: InputProps) {
63-
return <input id={props.id ?? createUniqueId()} />;
68+
const inputId = props.id ?? createUniqueId();
69+
70+
return (
71+
<>
72+
<label for={inputId}>{props.label}</label>
73+
<input id={inputId} />
74+
</>
75+
);
6476
}
6577
```

src/routes/reference/component-apis/lazy.mdx

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ tags:
1212
- imports
1313
version: "1.0"
1414
description: >-
15-
Lazy load components with code splitting to reduce bundle size and improve
16-
performance. Components load on-demand and integrate with Suspense.
15+
Create a component that loads its module lazily from a dynamic import.
1716
---
1817

19-
The `lazy` helper wraps a dynamic import and returns a component that loads on demand.
20-
Lazy components accept the same props as their eager counterparts and integrate with `<Suspense>` boundaries.
18+
`lazy` wraps a dynamic import and returns a component that loads its module on demand.
19+
The returned component accepts the same props as the loaded component and exposes `preload()`.
2120

2221
## Import
2322

@@ -27,10 +26,10 @@ import { lazy } from "solid-js";
2726

2827
## Type
2928

30-
```tsx
29+
```ts
3130
function lazy<T extends Component<any>>(
3231
fn: () => Promise<{ default: T }>
33-
): T & { preload: () => Promise<T> };
32+
): T & { preload: () => Promise<{ default: T }> };
3433
```
3534

3635
## Parameters
@@ -44,32 +43,42 @@ Dynamic import that resolves to the component module, exposing the component as
4443

4544
## Return value
4645

47-
`lazy` returns a renderable component compatible with `T`.
48-
The component exposes a `preload()` method that resolves the underlying module.
46+
- **Type:** `T & { preload: () => Promise<{ default: T }> }`
47+
48+
Returns a renderable component compatible with `T`.
49+
The returned component also exposes `preload()`.
50+
51+
`preload()` starts loading the module without rendering the component and returns the resolved module.
4952

50-
| Property | Type | Description |
51-
| --------- | ------------------ | ---------------------------------------------------------------------- |
52-
| `preload` | `() => Promise<T>` | Loads the module without rendering and returns the resolved component. |
53+
## Behavior
54+
55+
- Rendering a lazy component starts loading its module if it has not already been loaded.
56+
- Inside a [`<Suspense>`](/reference/components/suspense) boundary, the boundary shows its fallback while the module is loading.
57+
- Without a suspense boundary, the lazy component renders an empty string until the module resolves.
58+
- `preload()` starts the same module request without rendering the component.
5359

5460
## Examples
5561

5662
### Basic usage
5763

58-
```tsx title="app.tsx"
59-
import { lazy } from "solid-js";
64+
```tsx
65+
import { lazy, Suspense } from "solid-js";
6066

6167
const ComponentA = lazy(() => import("./ComponentA"));
6268

6369
function App(props: { title: string }) {
64-
return <ComponentA title={props.title} />;
70+
return (
71+
<Suspense fallback={<p>Loading...</p>}>
72+
<ComponentA title={props.title} />
73+
</Suspense>
74+
);
6575
}
6676
```
6777

6878
### Preloading nested lazy components
6979

7080
```tsx
71-
import { lazy } from "solid-js";
72-
import type { Component } from "solid-js";
81+
import { createSignal, lazy, Show, Suspense } from "solid-js";
7382

7483
const Nested = lazy(() => import("./Nested"));
7584

@@ -85,14 +94,16 @@ const ComponentWithPreload = () => {
8594
Preload Nested Component
8695
</button>
8796
<Show when={showNested()}>
88-
<Nested />
97+
<Suspense fallback={<p>Loading nested component...</p>}>
98+
<Nested />
99+
</Suspense>
89100
</Show>
90101
</div>
91102
);
92103
};
93104
```
94105

95-
## See also
106+
## Related
96107

97-
- [`Suspense`](https://docs.solidjs.com/reference/components/suspense)
108+
- [`Suspense`](/reference/components/suspense)
98109
- [Router preloading guide](/solid-router/advanced-concepts/preloading)

src/routes/reference/secondary-primitives/create-computed.mdx

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ tags:
1111
- tracking
1212
version: "1.0"
1313
description: >-
14-
Create immediate reactive computations with createComputed. Build custom
15-
primitives and handle side effects that respond to dependencies.
14+
Create an immediate reactive computation that runs synchronously when created
15+
and whenever its dependencies change.
1616
---
1717

18-
The `createComputed` function creates a reactive computation that runs _before_ the rendering phase.
19-
It is primarily used to synchronize state before rendering begins.
18+
`createComputed` creates an immediate reactive computation.
19+
It runs synchronously in the current execution context when created, then re-runs whenever its tracked dependencies change.
2020

2121
## Import
2222

@@ -83,41 +83,39 @@ It is used for identification in debugging tools like the [Solid Debugger](https
8383

8484
`createComputed` does not return a value.
8585

86+
## Behavior
87+
88+
- `createComputed` runs immediately when it is created.
89+
- It tracks reactive reads inside `fn` and re-runs synchronously when those dependencies change.
90+
- Unlike [`createMemo`](/reference/basic-reactivity/create-memo), it does not expose a derived accessor.
91+
- `createComputed` is primarily used to build reactive primitives. Application code that derives state usually wants [`createMemo`](/reference/basic-reactivity/create-memo) instead.
92+
8693
## Examples
8794

88-
### Basic usage
95+
### Build a writable derived signal
8996

9097
```tsx
91-
import { createComputed } from "solid-js";
92-
import { createStore } from "solid-js/store";
98+
import { createComputed, createSignal } from "solid-js";
9399

94-
type User = {
95-
name?: string;
96-
};
100+
function createWritableMemo<T>(fn: () => T) {
101+
const [value, setValue] = createSignal(fn());
97102

98-
type UserEditorProps = {
99-
user: User;
100-
};
101-
102-
function UserEditor(props: UserEditorProps) {
103-
const [formData, setFormData] = createStore<User>({
104-
name: "",
105-
});
106-
107-
// Update the store synchronously when props change.
108-
// This prevents a second render cycle.
109103
createComputed(() => {
110-
setFormData("name", props.user.name);
104+
setValue(fn());
111105
});
112106

107+
return value;
108+
}
109+
110+
function Counter() {
111+
const [count, setCount] = createSignal(1);
112+
const double = createWritableMemo(() => count() * 2);
113+
113114
return (
114-
<form>
115-
<h1>Editing: {formData.name}</h1>
116-
<input
117-
value={formData.name}
118-
onInput={(e) => setFormData("name", e.currentTarget.value)}
119-
/>
120-
</form>
115+
<>
116+
<p>{double()}</p>
117+
<button onClick={() => setCount((value) => value + 1)}>Increment</button>
118+
</>
121119
);
122120
}
123121
```

src/routes/reference/server-utilities/get-request-event.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ import { getRequestEvent } from "solid-js/web";
2323
## Type
2424

2525
```ts
26-
interface RequestEvent {
27-
request: Request;
28-
locals?: Record<string | number | symbol, any>;
29-
}
26+
import type { RequestEvent } from "solid-js/web";
3027

3128
function getRequestEvent(): RequestEvent | undefined;
3229
```
@@ -38,7 +35,8 @@ function getRequestEvent(): RequestEvent | undefined;
3835
## Behavior
3936

4037
- `getRequestEvent` is for managed server/request scope.
41-
- When available, the returned event includes the current `Request`. In the server type, it also includes `locals`.
38+
- When available, the returned event includes the current `Request` as `event.request`.
39+
- Depending on the server integration, the event can also expose request-scoped fields such as `response`, `locals`, or router state.
4240
- If no current request event is available, including outside managed async scope, `getRequestEvent` returns `undefined`.
4341

4442
## Examples
@@ -48,9 +46,11 @@ function getRequestEvent(): RequestEvent | undefined;
4846
```ts
4947
import { getRequestEvent } from "solid-js/web";
5048

51-
const event = getRequestEvent();
49+
function readAuthorizationHeader() {
50+
const event = getRequestEvent();
5251

53-
if (event) {
54-
const auth = event.request.headers.get("Authorization");
52+
return event?.request.headers.get("Authorization") ?? null;
5553
}
5654
```
55+
56+
This example reads the event during request-scoped server execution.

0 commit comments

Comments
 (0)