add fork_discarded error

pull/17004/head
Rich Harris 1 week ago
parent ae95b5fd64
commit 4f35c019fc

@ -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_discarded
```
Cannot commit a fork that was already committed or discarded (including as a result of a different fork being committed)
```
### fork_timing
```

@ -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_discarded
> Cannot commit a fork that was already committed or discarded (including as a result of a different fork being committed)
## fork_timing
> Cannot create a fork inside an effect or when state changes are pending

@ -261,6 +261,38 @@ export function flush_sync_in_effect() {
}
}
/**
* 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`);
}
}
/**
* Cannot commit a fork that was already committed or discarded (including as a result of a different fork being committed)
* @returns {never}
*/
export function fork_discarded() {
if (DEV) {
const error = new Error(`fork_discarded\nCannot commit a fork that was already committed or discarded (including as a result of a different fork being committed)\nhttps://svelte.dev/e/fork_discarded`);
error.name = 'Svelte error';
throw error;
} else {
throw new Error(`https://svelte.dev/e/fork_discarded`);
}
}
/**
* `getAbortSignal()` can only be called inside an effect or derived
* @returns {never}
@ -455,20 +487,4 @@ 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`);
}
}

@ -907,7 +907,7 @@ export function fork(fn) {
return {
commit: async () => {
if (!batches.has(batch)) {
throw new Error('Cannot commit this batch'); // TODO better error
e.fork_discarded();
}
batch.is_fork = false;

Loading…
Cancel
Save