Skip to content

Commit 3fee27b

Browse files
Sync svelte docs (#1550)
sync svelte docs Co-authored-by: svelte-docs-bot[bot] <196124396+svelte-docs-bot[bot]@users.noreply.github.com>
1 parent c598dfb commit 3fee27b

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

apps/svelte.dev/content/docs/svelte/03-template-syntax/19-await-expressions.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,6 @@ export default {
2424

2525
The experimental flag will be removed in Svelte 6.
2626

27-
## Boundaries
28-
29-
Currently, you can only use `await` inside a [`<svelte:boundary>`](svelte-boundary) with a `pending` snippet:
30-
31-
```svelte
32-
<svelte:boundary>
33-
<MyApp />
34-
35-
{#snippet pending()}
36-
<p>loading...</p>
37-
{/snippet}
38-
</svelte:boundary>
39-
```
40-
41-
This restriction will be lifted once Svelte supports asynchronous server-side rendering (see [caveats](#Caveats)).
42-
43-
> [!NOTE] In the [playground](/playground), your app is rendered inside a boundary with an empty pending snippet, so that you can use `await` without having to create one.
44-
4527
## Synchronized updates
4628

4729
When an `await` expression depends on a particular piece of state, changes to that state will not be reflected in the UI until the asynchronous work has completed, so that the UI is not left in an inconsistent state. In other words, in an example like [this](/playground/untitled#H4sIAAAAAAAAE42QsWrDQBBEf2VZUkhYRE4gjSwJ0qVMkS6XYk9awcFpJe5Wdoy4fw-ycdykSPt2dpiZFYVGxgrf2PsJTlPwPWTcO-U-xwIH5zli9bminudNtwEsbl-v8_wYj-x1Y5Yi_8W7SZRFI1ZYxy64WVsjRj0rEDTwEJWUs6f8cKP2Tp8vVIxSPEsHwyKdukmA-j6jAmwO63Y1SidyCsIneA_T6CJn2ZBD00Jk_XAjT4tmQwEv-32eH6AsgYK6wXWOPPTs6Xy1CaxLECDYgb3kSUbq8p5aaifzorCt0RiUZbQcDIJ10ldH8gs3K6X2Xzqbro5zu1KCHaw2QQPrtclvwVSXc2sEC1T-Vqw0LJy-ClRy_uSkx2ogHzn9ADZ1CubKAQAA)...
@@ -100,7 +82,9 @@ let b = $derived(await two());
10082
10183
## Indicating loading states
10284

103-
In addition to the nearest boundary's [`pending`](svelte-boundary#Properties-pending) snippet, you can indicate that asynchronous work is ongoing with [`$effect.pending()`]($effect#$effect.pending).
85+
To render placeholder UI, you can wrap content in a `<svelte:boundary>` with a [`pending`](svelte-boundary#Properties-pending) snippet. This will be shown when the boundary is first created, but not for subsequent updates, which are globally coordinated.
86+
87+
After the contents of a boundary have resolved for the first time and replaced the `pending` snippet, you can detect subsequent async work with [`$effect.pending()`]($effect#$effect.pending). This is what you would use display a "we're asynchronously validating your input" spinner next to a form field, for example.
10488

10589
You can also use [`settled()`](svelte#settled) to get a promise that resolves when the current update is complete:
10690

@@ -134,6 +118,24 @@ async function onclick() {
134118

135119
Errors in `await` expressions will bubble to the nearest [error boundary](svelte-boundary).
136120

121+
## Server-side rendering
122+
123+
Svelte supports asynchronous server-side rendering (SSR) with the `render(...)` API. To use it, simply await the return value:
124+
125+
```js
126+
/// file: server.js
127+
import { render } from 'svelte/server';
128+
import App from './App.svelte';
129+
130+
const { head, body } = +++await+++ render(App);
131+
```
132+
133+
> [!NOTE] If you're using a framework like SvelteKit, this is done on your behalf.
134+
135+
If a `<svelte:boundary>` with a `pending` snippet is encountered during SSR, that snippet will be rendered while the rest of the content is ignored. All `await` expressions encountered outside boundaries with `pending` snippets will resolve and render their contents prior to `await render(...)` returning.
136+
137+
> [!NOTE] In the future, we plan to add a streaming implementation that renders the content in the background.
138+
137139
## Caveats
138140

139141
As an experimental feature, the details of how `await` is handled (and related APIs like `$effect.pending()`) are subject to breaking changes outside of a semver major release, though we intend to keep such changes to a bare minimum.

0 commit comments

Comments
 (0)