You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 103bcc3
Browse filesBrowse the repository at this point in the historyBrowse files
docs: when to use createDeferred instead of latest or createMemo (#1693)
Adds a "Let a panel lag" section to the async reactivity concept page, a
row for it in the update decision table, and caveats on the reference page
contrasting it with reading every consumer through latest (solidjs/solid#4773).
Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE
Co-authored-by: Claude <noreply@anthropic.com>
"`createDeferred` is not `latest` on every consumer. `latest` shows a value now while the update stays held for every other reader; a deferred memo is not part of the update, so nothing waits for it. See [Let a panel lag](/concepts/async-reactivity#let-a-panel-lag-createdeferred).",
109
+
"Use it for data that may fall behind the rest of the page without making it wrong, such as an independent widget or a feed. Data that must agree with the rest of the page belongs in `createMemo`.",
110
+
"Its first load still suspends to the nearest `Loading` boundary, unless `loadingValue` is set.",
| Nothing change until everything that depends on the input is ready | The default. Add [`isPending`](#another-answer-is-coming-ispending) to acknowledge the click. |
247
-
| The control they touched reflect their input now, and the content wait |[`latest`](#show-the-input-now-latest) on the control, `isPending` to dim the content. |
248
-
| A placeholder in place of the content for the changed subject |[`<Loading on={key}>`](#show-a-placeholder-again-loading-on) around that content. |
| Nothing change until everything that depends on the input is ready | The default. Add [`isPending`](#another-answer-is-coming-ispending) to acknowledge the click. |
247
+
| The control they touched reflect their input now, and the content wait |[`latest`](#show-the-input-now-latest) on the control, `isPending` to dim the content. |
248
+
| A placeholder in place of the content for the changed subject |[`<Loading on={key}>`](#show-a-placeholder-again-loading-on) around that content. |
249
+
| The input and the rest of the page change now, and one panel keep its old content until its own answer lands |[`createDeferred`](#let-a-panel-lag-createdeferred) for that panel's data, `isPending` to dim it. |
249
250
250
251
The first two rows are the same screen: the tab highlight moves at once, the content stays and dims, the content swaps when it is ready.
251
252
That is the standard interaction for a held update, and the rest of this section shows the pieces.
252
253
The third row is for content that should not stay on screen when its subject changes, such as a panel for a different account.
254
+
The fourth row is for a panel that may fall behind the rest of the page without making it wrong, such as the ten-second audit log.
253
255
254
256
The hold applies only to updates.
255
257
Each panel's first load still reaches the nearest `Loading` boundary, and nested boundaries let panels appear as their own first data arrives.
@@ -389,6 +391,46 @@ This is the everyday shape of a held update, not a special case.
389
391
Reading data through `latest` shows a result before the rest of the update has agreed on it, so a panel can show the new period's numbers while the selector still shows the old period.
390
392
When you want the control to lead, use `latest` on the control; when you want a panel to show a placeholder, use the next section.
391
393
394
+
## Let a panel lag: `createDeferred`
395
+
396
+
`latest` changes what one reader shows.
397
+
The update is still held: every plain reader of the input waits, and the page commits when the slowest answer lands.
398
+
When a panel may keep its previous answer while the next one loads, and the rest of the page should not wait for it, create the panel's data with [`createDeferred`](/reference/solid-js/reactivity/create-deferred) instead of `createMemo`:
After its first answer, a refetch of a deferred memo holds nothing.
413
+
When the period changes, the selector and the other two panels change at once.
414
+
The audit panel keeps its old entries, dims through `isPending`, and shows the new entries when its own request lands.
415
+
416
+
The two APIs look alike but answer different questions:
417
+
418
+
-`latest` is on the reader. This control shows the input now; the content still waits with the update.
419
+
-`createDeferred` is on the source. No reader waits for this answer, so the update does not wait for it either.
420
+
421
+
So `createDeferred` is not the same as reading every consumer through `latest`.
422
+
With `latest`, the update is still held for every plain read of the input until the slow answer lands.
423
+
With `createDeferred`, the slow answer is no longer part of the update at all.
424
+
425
+
Reach for `createDeferred` when the async work can lag without making the page wrong: an independent widget, a feed, or search suggestions.
426
+
Keep `createMemo` for data that must agree with the rest of the page, such as totals that must add up or the details of the selected item.
427
+
428
+
:::note
429
+
A deferred memo may lag, but it never leads.
430
+
Its first load is a first load like any other: readers suspend to the nearest `Loading` boundary.
431
+
A refetch that reads a value another update is still holding lands with that update, so the panel never shows an answer the rest of the page has not committed to.
432
+
:::
433
+
392
434
## Show a placeholder again: `Loading on`
393
435
394
436
Once a `Loading` boundary has shown content, a later update does not bring the fallback back; the content stays and the update is held.
-`createDeferred` is not `latest` on every consumer. `latest` shows a value now while the update stays held for every other reader; a deferred memo is not part of the update, so nothing waits for it. See [Let a panel lag](/concepts/async-reactivity#let-a-panel-lag-createdeferred).
70
+
- Use it for data that may fall behind the rest of the page without making it wrong, such as an independent widget or a feed. Data that must agree with the rest of the page belongs in `createMemo`.
71
+
- Its first load still suspends to the nearest `Loading` boundary, unless `loadingValue` is set.
0 commit comments