add a fork_timing error, regenerate

pull/17004/head
Rich Harris 1 week ago
parent b213aeac71
commit 7a66321441

@ -146,6 +146,12 @@ The `flushSync()` function can be used to flush any pending effects synchronousl
This restriction only applies when using the `experimental.async` option, which will be active by default in Svelte 6.
### fork_timing
```
Cannot create a fork inside an effect or when state changes are pending
```
### get_abort_signal_outside_reaction
```

@ -112,6 +112,10 @@ The `flushSync()` function can be used to flush any pending effects synchronousl
This restriction only applies when using the `experimental.async` option, which will be active by default in Svelte 6.
## fork_timing
> Cannot create a fork inside an effect or when state changes are pending
## get_abort_signal_outside_reaction
> `getAbortSignal()` can only be called inside an effect or derived

@ -455,4 +455,20 @@ export function svelte_boundary_reset_onerror() {
} else {
throw new Error(`https://svelte.dev/e/svelte_boundary_reset_onerror`);
}
}
/**
* Cannot create a fork inside an effect or when state changes are pending
* @returns {never}
*/
export function fork_timing() {
if (DEV) {
const error = new Error(`fork_timing\nCannot create a fork inside an effect or when state changes are pending\nhttps://svelte.dev/e/fork_timing`);
error.name = 'Svelte error';
throw error;
} else {
throw new Error(`https://svelte.dev/e/fork_timing`);
}
}

@ -895,7 +895,7 @@ export function fork(fn) {
}
if (current_batch !== null) {
throw new Error('cannot fork here'); // TODO better error
e.fork_timing();
}
const batch = Batch.ensure();

@ -448,7 +448,19 @@ declare module 'svelte' {
* Returns void if no callback is provided, otherwise returns the result of calling the callback.
* */
export function flushSync<T = void>(fn?: (() => T) | undefined): T;
/**
* Creates a 'fork', in which state changes are evaluated but not applied to the DOM.
* This is useful for speculatively loading data (for example) when you suspect that
* the user is about to take some action.
*
* Frameworks like SvelteKit can use this to preload data when the user touches or
* hovers over a link, making any subsequent navigation feel instantaneous.
*
* The `fn` parameter is a synchronous function that modifies some state. The
* state changes will be reverted after the fork is initialised, then reapplied
* if and when the fork is eventually committed.
*
* */
export function fork(fn: () => void): {
commit: () => void;
discard: () => void;

Loading…
Cancel
Save