error if missing experimental flag

pull/17004/head
Rich Harris 3 weeks ago
parent a2b892bb36
commit 53cc91dd0c

@ -130,6 +130,12 @@ $effect(() => {
Often when encountering this issue, the value in question shouldn't be state (for example, if you are pushing to a `logs` array in an effect, make `logs` a normal array rather than `$state([])`). In the rare cases where you really _do_ need to write to state in an effect — [which you should avoid]($effect#When-not-to-use-$effect) — you can read the state with [untrack](svelte#untrack) to avoid adding it as a dependency.
### experimental_async_fork
```
Cannot use `fork(...)` unless the `experimental.async` compiler option is `true`
```
### flush_sync_in_effect
```

@ -100,6 +100,10 @@ $effect(() => {
Often when encountering this issue, the value in question shouldn't be state (for example, if you are pushing to a `logs` array in an effect, make `logs` a normal array rather than `$state([])`). In the rare cases where you really _do_ need to write to state in an effect — [which you should avoid]($effect#When-not-to-use-$effect) — you can read the state with [untrack](svelte#untrack) to avoid adding it as a dependency.
## experimental_async_fork
> Cannot use `fork(...)` unless the `experimental.async` compiler option is `true`
## flush_sync_in_effect
> Cannot use `flushSync` inside an effect

@ -439,4 +439,20 @@ export function svelte_boundary_reset_onerror() {
} else {
throw new Error(`https://svelte.dev/e/svelte_boundary_reset_onerror`);
}
}
/**
* Cannot use `fork(...)` unless the `experimental.async` compiler option is `true`
* @returns {never}
*/
export function experimental_async_fork() {
if (DEV) {
const error = new Error(`experimental_async_fork\nCannot use \`fork(...)\` unless the \`experimental.async\` compiler option is \`true\`\nhttps://svelte.dev/e/experimental_async_fork`);
error.name = 'Svelte error';
throw error;
} else {
throw new Error(`https://svelte.dev/e/experimental_async_fork`);
}
}

@ -877,6 +877,10 @@ export function eager(fn) {
* @returns {{ commit: () => void, discard: () => void }}
*/
export function fork(fn) {
if (!async_mode_flag) {
e.experimental_async_fork();
}
if (current_batch !== null) {
throw new Error('cannot fork here'); // TODO better error
}

Loading…
Cancel
Save