Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/signals/src/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,16 @@ export function setStrictRead(v: string | false): string | false {
* Use `untrack` inside a memo or effect when you need to read a signal once
* without making the surrounding computation depend on its future changes.
*
* `untrack` stops dependency tracking, not async settlement. Reading an
* uninitialized async source still suspends the owning computation; it runs
* again when that source first resolves. Afterward, the untracked read is a
* snapshot and does not subscribe the computation to later changes.
*
* If the first read must return immediately, give the async source a
* `loadingValue` before reading it with `untrack`. `isPending` and `latest`
* inspect updates to an existing value; neither supplies a missing initial
* value.
*
* Pass a `strictReadLabel` string to enable a dev-mode warning: any reactive
* read inside `fn` that isn't inside a nested tracking scope will log a
* warning naming the label.
Expand All @@ -1530,6 +1540,9 @@ export function setStrictRead(v: string | false): string | false {
* log(snapshot);
* }
* );
*
* const color = createMemo<string>(() => fetchColor(), { loadingValue: "gray" });
* const initialColor = untrack(color); // "gray" while the fetch is unresolved
* ```
*/
export function untrack<T>(fn: () => T, strictReadLabel?: string | false): T {
Expand Down
Loading