add effect_pending_outside_reaction error

pull/15844/head
Rich Harris 3 months ago
parent 70d4a3d96e
commit 4fc61c7fba

@ -80,6 +80,12 @@ Effect cannot be created inside a `$derived` value that was not itself created i
`%rune%` can only be used inside an effect (e.g. during component initialisation) `%rune%` can only be used inside an effect (e.g. during component initialisation)
``` ```
### effect_pending_outside_reaction
```
`$effect.pending()` can only be called inside an effect or derived
```
### effect_update_depth_exceeded ### effect_update_depth_exceeded
``` ```

@ -54,6 +54,10 @@ See the [migration guide](/docs/svelte/v5-migration-guide#Components-are-no-long
> `%rune%` can only be used inside an effect (e.g. during component initialisation) > `%rune%` can only be used inside an effect (e.g. during component initialisation)
## effect_pending_outside_reaction
> `$effect.pending()` can only be called inside an effect or derived
## effect_update_depth_exceeded ## effect_update_depth_exceeded
> Maximum update depth exceeded. This can happen when a reactive block or effect repeatedly sets a new value. Svelte limits the number of nested updates to prevent infinite loops > Maximum update depth exceeded. This can happen when a reactive block or effect repeatedly sets a new value. Svelte limits the number of nested updates to prevent infinite loops

@ -1,4 +1,5 @@
import { DEV } from 'esm-env'; import { DEV } from 'esm-env';
export * from '../shared/errors.js';
/** /**
* MESSAGE * MESSAGE

@ -1,3 +1,5 @@
export * from '../shared/errors.js';
/** /**
* MESSAGE * MESSAGE
* @param {string} PARAMETER * @param {string} PARAMETER

@ -20,7 +20,7 @@ import {
} from '../hydration.js'; } from '../hydration.js';
import { get_next_sibling } from '../operations.js'; import { get_next_sibling } from '../operations.js';
import { queue_micro_task } from '../task.js'; import { queue_micro_task } from '../task.js';
import * as e from '../../../shared/errors.js'; import * as e from '../../errors.js';
import { DEV } from 'esm-env'; import { DEV } from 'esm-env';
import { from_async_derived, set_from_async_derived } from '../../reactivity/deriveds.js'; import { from_async_derived, set_from_async_derived } from '../../reactivity/deriveds.js';
import { Batch } from '../../reactivity/batch.js'; import { Batch } from '../../reactivity/batch.js';
@ -454,8 +454,11 @@ function exit() {
} }
export function pending() { export function pending() {
// TODO throw helpful error if called outside an effect if (active_effect === null) {
const boundary = /** @type {Effect} */ (active_effect).b; e.effect_pending_outside_reaction();
}
var boundary = active_effect.b;
if (boundary === null) { if (boundary === null) {
return 0; // TODO eventually we will need this to be global return 0; // TODO eventually we will need this to be global

@ -2,6 +2,8 @@
import { DEV } from 'esm-env'; import { DEV } from 'esm-env';
export * from '../shared/errors.js';
/** /**
* Cannot create a `$derived(...)` with an `await` expression outside of an effect tree * Cannot create a `$derived(...)` with an `await` expression outside of an effect tree
* @returns {never} * @returns {never}
@ -195,6 +197,22 @@ export function effect_orphan(rune) {
} }
} }
/**
* `$effect.pending()` can only be called inside an effect or derived
* @returns {never}
*/
export function effect_pending_outside_reaction() {
if (DEV) {
const error = new Error(`effect_pending_outside_reaction\n\`$effect.pending()\` can only be called inside an effect or derived\nhttps://svelte.dev/e/effect_pending_outside_reaction`);
error.name = 'Svelte error';
throw error;
} else {
throw new Error(`https://svelte.dev/e/effect_pending_outside_reaction`);
}
}
/** /**
* Maximum update depth exceeded. This can happen when a reactive block or effect repeatedly sets a new value. Svelte limits the number of nested updates to prevent infinite loops * Maximum update depth exceeded. This can happen when a reactive block or effect repeatedly sets a new value. Svelte limits the number of nested updates to prevent infinite loops
* @returns {never} * @returns {never}

@ -1,6 +1,6 @@
/* This file is generated by scripts/process-messages/index.js. Do not edit! */ /* This file is generated by scripts/process-messages/index.js. Do not edit! */
export * from '../shared/errors.js';
/** /**
* `%name%(...)` is not available on the server * `%name%(...)` is not available on the server

Loading…
Cancel
Save