|
| 1 | +## async_derived_orphan |
| 2 | + |
| 3 | +> Cannot create a `$derived(...)` with an `await` expression outside of an effect tree |
| 4 | +
|
| 5 | +In Svelte there are two types of reaction — [`$derived`](/docs/svelte/$derived) and [`$effect`](/docs/svelte/$effect). Deriveds can be created anywhere, because they run _lazily_ and can be [garbage collected](https://developer.mozilla.org/en-US/docs/Glossary/Garbage_collection) if nothing references them. Effects, by contrast, keep running eagerly whenever their dependencies change, until they are destroyed. |
| 6 | + |
| 7 | +Because of this, effects can only be created inside other effects (or [effect roots](/docs/svelte/$effect#$effect.root), such as the one that is created when you first mount a component) so that Svelte knows when to destroy them. |
| 8 | + |
| 9 | +Some sleight of hand occurs when a derived contains an `await` expression: Since waiting until we read `{await getPromise()}` to call `getPromise` would be too late, we use an effect to instead call it proactively, notifying Svelte when the value is available. But since we're using an effect, we can only create asynchronous deriveds inside another effect. |
| 10 | + |
1 | 11 | ## bind_invalid_checkbox_value
|
2 | 12 |
|
3 | 13 | > Using `bind:value` together with a checkbox input is not allowed. Use `bind:checked` instead
|
@@ -44,10 +54,22 @@ See the [migration guide](/docs/svelte/v5-migration-guide#Components-are-no-long
|
44 | 54 |
|
45 | 55 | > `%rune%` can only be used inside an effect (e.g. during component initialisation)
|
46 | 56 |
|
| 57 | +## effect_pending_outside_reaction |
| 58 | + |
| 59 | +> `$effect.pending()` can only be called inside an effect or derived |
| 60 | +
|
47 | 61 | ## effect_update_depth_exceeded
|
48 | 62 |
|
49 | 63 | > 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
|
50 | 64 |
|
| 65 | +## flush_sync_in_effect |
| 66 | + |
| 67 | +> Cannot use `flushSync` inside an effect |
| 68 | +
|
| 69 | +The `flushSync()` function can be used to flush any pending effects synchronously. It cannot be used if effects are currently being flushed — in other words, you can call it after a state change but _not_ inside an effect. |
| 70 | + |
| 71 | +This restriction only applies when using the `experimental.async` option, which will be active by default in Svelte 6. |
| 72 | + |
51 | 73 | ## get_abort_signal_outside_reaction
|
52 | 74 |
|
53 | 75 | > `getAbortSignal()` can only be called inside an effect or derived
|
@@ -76,6 +98,12 @@ See the [migration guide](/docs/svelte/v5-migration-guide#Components-are-no-long
|
76 | 98 |
|
77 | 99 | > The `%rune%` rune is only available inside `.svelte` and `.svelte.js/ts` files
|
78 | 100 |
|
| 101 | +## set_context_after_init |
| 102 | + |
| 103 | +> `setContext` must be called when a component first initializes, not in a subsequent effect or after an `await` expression |
| 104 | +
|
| 105 | +This restriction only applies when using the `experimental.async` option, which will be active by default in Svelte 6. |
| 106 | + |
79 | 107 | ## state_descriptors_fixed
|
80 | 108 |
|
81 | 109 | > Property descriptors defined on `$state` objects must contain `value` and always be `enumerable`, `configurable` and `writable`.
|
|
0 commit comments