From e888b5b2d4a4d90ca8b774b1578b9253ddf1d4c9 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 3 Jul 2025 15:48:59 -0400 Subject: [PATCH] flesh out await_outside_boundary message --- .../docs/98-reference/.generated/client-errors.md | 4 ++-- .../docs/98-reference/.generated/shared-errors.md | 14 +++++++++++++- packages/svelte/messages/client-errors/errors.md | 4 ++-- packages/svelte/messages/shared-errors/errors.md | 14 +++++++++++++- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/documentation/docs/98-reference/.generated/client-errors.md b/documentation/docs/98-reference/.generated/client-errors.md index 3f13edf338..1efc3434ab 100644 --- a/documentation/docs/98-reference/.generated/client-errors.md +++ b/documentation/docs/98-reference/.generated/client-errors.md @@ -6,9 +6,9 @@ Cannot create a `$derived(...)` with an `await` expression outside of an effect tree ``` -In Svelte there are two types of reaction — [`$derived`](https://svelte.dev/docs/svelte/$derived) and [`$effect`](https://svelte.dev/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. +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. -Because of this, effects can only be created inside other effects (or [effect roots](https://svelte.dev/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. +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. 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. diff --git a/documentation/docs/98-reference/.generated/shared-errors.md b/documentation/docs/98-reference/.generated/shared-errors.md index ac31e22c75..de34b3f5da 100644 --- a/documentation/docs/98-reference/.generated/shared-errors.md +++ b/documentation/docs/98-reference/.generated/shared-errors.md @@ -6,7 +6,19 @@ Cannot await outside a `` with a `pending` snippet ``` -TODO +The `await` keyword can only appear in a `$derived(...)` or template expression, or at the top level of a component's `