Skip to main content
The fork() function allows you to create speculative state updates that happen in parallel, which can later be committed or discarded. This is useful for prefetching data or preparing UI changes in advance.
The fork() function requires experimental async mode to be enabled in your Svelte configuration.

Import

Signature

Parameters

fn
() => void
required
A function that performs state updates within the fork

Returns

Fork
object
An object with methods to commit or discard the forked state

Usage

Prefetching data

Speculative UI updates

Notes

  • Forks must be created outside of any existing batch
  • State changes within a fork are isolated until committed
  • Multiple forks can exist simultaneously
  • Requires experimental async mode

See also

  • flushSync - Synchronously flush state updates
  • settled - Wait for all effects to settle