Skip to content

Commit ed5a2c7

Browse files
committed
improve accuracy of docs
1 parent b6c3f87 commit ed5a2c7

File tree

4 files changed

+100
-36
lines changed

4 files changed

+100
-36
lines changed

src/routes/reference/components/no-hydration.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ Content inside the boundary.
3939

4040
- **Type:** `JSX.Element`
4141

42-
Returns the server-rendered children.
42+
Returns the children during server and client-only rendering.
4343

4444
## Behavior
4545

4646
- During server rendering, children inside `<NoHydration>` render normally.
4747
- During client hydration, Solid leaves the existing server-rendered DOM in place and does not hydrate that subtree.
48+
- In client-only rendering, `<NoHydration>` renders its children normally.
4849
- Interactive behavior inside the boundary does not hydrate on the client.
49-
- Placing `<Hydration>` inside `<NoHydration>` does not override the no-hydration behavior.
5050

5151
## Examples
5252

@@ -56,9 +56,11 @@ Returns the server-rendered children.
5656
function Example() {
5757
return (
5858
<div>
59-
<button>Interactive button</button>
59+
<button onClick={() => console.log("hydrated")}>Hydrated button</button>
6060
<NoHydration>
61-
<div innerHTML={"<strong>Server-rendered only</strong>"} />
61+
<div>
62+
<strong>Rendered on the server without hydration</strong>
63+
</div>
6264
</NoHydration>
6365
</div>
6466
);

src/routes/reference/components/suspense-list.mdx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Order used to reveal child boundaries.
5656

5757
- **Type:** `"collapsed" | "hidden"`
5858

59-
Controls fallback visibility for later items after the first still-pending item.
59+
Controls fallback visibility for later items after the first still-pending item in ordered reveal modes.
6060

6161
## Return value
6262

@@ -71,23 +71,36 @@ Returns the coordinated suspense boundaries.
7171
- `revealOrder="together"` reveals all items only after all coordinated boundaries are ready.
7272
- With `tail="collapsed"`, the first still-pending item can keep its fallback visible, while later pending items hide theirs.
7373
- With `tail="hidden"`, pending items after the first still-pending item hide their fallbacks.
74+
- `<SuspenseList>` coordinates child suspense boundaries. It does not suspend by itself.
7475

7576
## Examples
7677

7778
### Basic usage
7879

7980
```tsx
80-
const resource = {
81-
user: { name: "Ada" },
82-
posts: ["First post"],
81+
import { createResource, Suspense } from "solid-js";
82+
83+
const delayed = async <T,>(value: T, ms: number) => {
84+
await new Promise((resolve) => setTimeout(resolve, ms));
85+
return value;
8386
};
8487

88+
function ProfileDetails() {
89+
const [user] = createResource(() => delayed({ name: "Ada" }, 500));
90+
return <h2>{user()?.name}</h2>;
91+
}
92+
93+
function ProfileTimeline() {
94+
const [posts] = createResource(() => delayed(["First post"], 1000));
95+
return <ul>{posts()?.map((post) => <li>{post}</li>)}</ul>;
96+
}
97+
8598
<SuspenseList revealOrder="forwards" tail="collapsed">
8699
<Suspense fallback={<h2>Loading profile...</h2>}>
87-
<ProfileDetails user={resource.user} />
100+
<ProfileDetails />
88101
</Suspense>
89102
<Suspense fallback={<h2>Loading posts...</h2>}>
90-
<ProfileTimeline posts={resource.posts} />
103+
<ProfileTimeline />
91104
</Suspense>
92105
</SuspenseList>;
93106
```

src/routes/reference/components/suspense.mdx

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ tags:
1212
- components
1313
version: "1.0"
1414
description: >-
15-
Render fallback content while resources read under the boundary are pending.
15+
Render fallback content while suspense-tracked async dependencies under the boundary are pending.
1616
---
1717

18-
`<Suspense>` renders `fallback` while resources read under its boundary are pending.
18+
`<Suspense>` renders `fallback` while suspense-tracked async dependencies under its boundary are pending.
1919

2020
## Import
2121

@@ -38,7 +38,7 @@ function Suspense(props: {
3838

3939
- **Type:** `JSX.Element`
4040

41-
Content rendered while tracked resources are pending.
41+
Content rendered while suspense-tracked async dependencies are pending.
4242

4343
### `children`
4444

@@ -50,34 +50,68 @@ Subtree inside the suspense boundary.
5050

5151
- **Type:** `JSX.Element`
5252

53-
Returns the rendered subtree or `fallback` content depending on pending tracked resources.
53+
Returns the rendered subtree or `fallback` content depending on pending suspense-tracked async dependencies.
5454

5555
## Behavior
5656

57-
- When a resource is read inside the boundary, `<Suspense>` renders `fallback` until the pending tracked resources resolve.
58-
- `<Suspense>` is non-blocking: the subtree can continue running before the boundary reveals the resolved content in the DOM.
59-
- Nested suspense boundaries handle resources read under the nearest boundary.
57+
- When a suspense-tracked async dependency is read inside the boundary, `<Suspense>` renders `fallback` until the pending work resolves.
58+
- `<Suspense>` is non-blocking: the subtree can continue running and create reactive owners before the boundary reveals the resolved content in the DOM.
59+
- Nested suspense boundaries handle suspense-tracked async dependencies under the nearest boundary.
6060
- `onMount` and `createEffect` inside the suspended subtree run after the boundary resolves.
6161

6262
## Examples
6363

6464
### Basic usage
6565

6666
```tsx
67-
<Suspense fallback={<LoadingSpinner />}>
68-
<AsyncComponent />
69-
</Suspense>
67+
import { createResource } from "solid-js";
68+
69+
const fetchMessage = async () => {
70+
await new Promise((resolve) => setTimeout(resolve, 1000));
71+
return "Loaded";
72+
};
73+
74+
function AsyncMessage() {
75+
const [message] = createResource(fetchMessage);
76+
return <p>{message()}</p>;
77+
}
78+
79+
<Suspense fallback={<p>Loading...</p>}>
80+
<AsyncMessage />
81+
</Suspense>;
7082
```
7183

7284
### Nested suspense
7385

7486
```tsx
87+
import { createResource } from "solid-js";
88+
89+
const fetchTitle = async () => {
90+
await new Promise((resolve) => setTimeout(resolve, 500));
91+
return "Profile";
92+
};
93+
94+
const fetchDetails = async () => {
95+
await new Promise((resolve) => setTimeout(resolve, 1000));
96+
return "Details loaded";
97+
};
98+
99+
function Title() {
100+
const [title] = createResource(fetchTitle);
101+
return <h1>{title()}</h1>;
102+
}
103+
104+
function Details() {
105+
const [details] = createResource(fetchDetails);
106+
return <p>{details()}</p>;
107+
}
108+
75109
<Suspense fallback={<div>Loading page...</div>}>
76-
<h1>{title()}</h1>
77-
<Suspense fallback={<div>Loading details</div>}>
78-
<DataComponent>{data()}</DataComponent>
110+
<Title />
111+
<Suspense fallback={<div>Loading details...</div>}>
112+
<Details />
79113
</Suspense>
80-
</Suspense>
114+
</Suspense>;
81115
```
82116

83117
## Related

src/routes/reference/components/switch-and-match.mdx

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,26 +91,41 @@ Returns the selected branch or the `fallback` content.
9191

9292
- `<Switch>` evaluates its child `<Match>` elements in order and renders only the first truthy branch.
9393
- If no branch matches, `<Switch>` renders `fallback`.
94-
- With `keyed={false}`, function children in `<Match>` receive an accessor that can only be read while that branch remains selected. With `keyed={true}`, they receive the value directly.
94+
- Function children in `<Match>` are wrapped in [`untrack`](/reference/reactive-utilities/untrack).
95+
- With `keyed={false}`, function children in `<Match>` receive an accessor that can only be read while that branch remains selected. Replacing one truthy value with another truthy value does not recreate the child block.
96+
- With `keyed={true}`, function children receive the current value directly, and changing the `when` value recreates the child block even when it remains truthy.
9597

9698
## Examples
9799

98100
### Basic usage
99101

100102
```tsx
101-
<Switch fallback={<p>Unknown status</p>}>
102-
<Match when={state.status === "loading"}>
103-
<p>Loading...</p>
104-
</Match>
105-
<Match when={state.status === "success"}>
106-
<p>Saved</p>
107-
</Match>
108-
<Match when={state.status === "error"}>
109-
<p>Failed</p>
110-
</Match>
111-
</Switch>
103+
import { createSignal } from "solid-js";
104+
105+
const [status, setStatus] = createSignal<"loading" | "success" | "error">(
106+
"loading"
107+
);
108+
109+
<>
110+
<button onClick={() => setStatus("loading")}>Loading</button>
111+
<button onClick={() => setStatus("success")}>Success</button>
112+
<button onClick={() => setStatus("error")}>Error</button>
113+
114+
<Switch fallback={<p>Unknown status</p>}>
115+
<Match when={status() === "loading"}>
116+
<p>Loading...</p>
117+
</Match>
118+
<Match when={status() === "success"}>
119+
<p>Saved</p>
120+
</Match>
121+
<Match when={status() === "error"}>
122+
<p>Failed</p>
123+
</Match>
124+
</Switch>
125+
</>;
112126
```
113127

114128
## Related
115129

116130
- [`<Show>`](/reference/components/show)
131+
- [`untrack`](/reference/reactive-utilities/untrack)

0 commit comments

Comments
 (0)