Await & Streaming
A plain {#await} block works the way Svelte defines it: the server renders the pending branch and the browser resolves the promise after hydrating. To resolve a block on the server and stream the result in the same response, mark it with <!-- absolute:stream -->.
#Plain {#await}
Write {#await} as you would in any Svelte app. The server sends the pending branch. The page hydrates, the promise resolves in the browser, and Svelte renders the {:then} or {:catch} branch. Branches can hold components and logic blocks. No handler option is needed.
<!-- frontend/svelte/pages/Activity.svelte -->
<script lang="ts">
import UpdateList from '../components/UpdateList.svelte';
let { userName }: { userName: string } = $props();
const activity = getActivity();
</script>
<h1>Hello, {userName}</h1>
{#await activity}
<p>Loading activity…</p>
{:then updates}
{#if updates.length > 0}
<UpdateList {updates} />
{:else}
<p>Nothing new.</p>
{/if}
{:catch error}
<p>Could not load activity: {error.message}</p>
{/await}#Streaming a Block
Put <!-- absolute:stream --> directly before an {#await} block. The server sends the page with the pending branch, resolves the promise itself, and streams the resolved HTML into the same response. The pending branch is replaced without a second request.
<!-- frontend/svelte/pages/Activity.svelte -->
<script lang="ts">
let { userName }: { userName: string } = $props();
</script>
<h1>Hello, {userName}</h1>
<!-- absolute:stream -->
{#await getActivityCount()}
<p>Loading activity…</p>
{:then count}
<p>{count} updates since your last visit</p>
{:catch error}
<p>Could not load activity: {error.message}</p>
{/await}#Handler Option
A streamed block needs collectStreamingSlots: true on the page's handler. Without it the block stays on its pending branch, and AbsoluteJS logs a warning that names the option.
// backend/server.ts
import { asset } from '@absolutejs/absolute';
import { handleSveltePageRequest } from '@absolutejs/absolute/svelte';
import type Activity from '../frontend/svelte/pages/Activity.svelte';
new Elysia().get('/activity', () =>
handleSveltePageRequest<typeof Activity>({
collectStreamingSlots: true,
indexPath: asset(manifest, 'ActivityIndex'),
pagePath: asset(manifest, 'Activity'),
props: { userName: 'Ada' }
})
);#Streamed Branches
A streamed block's branches are sent as HTML, not Svelte markup. Each branch can hold elements, {expressions} and {@html}. Expressions are escaped the way Svelte escapes them, in text and in attribute values, so a value with markup in it shows as text. {@html value} is inserted as it is, as in Svelte.
The component's <style> applies inside streamed branches, as it does in the rest of the component. Elements in the pending, {:then} and {:catch} branches get the component's scoped class.
A component, {#if}, {#each} or another logic block inside a streamed branch fails the build:
error: /home/you/app/src/frontend/svelte/pages/Activity.svelte:
the then branch of a streamed {#await} holds Svelte markup (<U…)
(<!-- absolute:stream --> streams plain HTML; remove the directive
to let Svelte render the block and hydrate it)An event handler such as onclick={…}, a directive such as class:active={…} or a spread fails the build too. They need Svelte to run in the browser.
A streamed block needs a pending branch, one {:then} and at most one {:catch}, in that order. The shorthand {#await promise then value} has no pending branch, so it can't be streamed. A page that streams a block is not hydrated, because the streamed HTML isn't Svelte's to claim. Pages that only use plain {#await} hydrate as usual.
#Choosing
Use a plain block when the result needs components, logic or interactivity. Stream a block when the result is simple HTML and you want it in the first response.
| Aspect | Plain {#await} | absolute:stream |
|---|---|---|
| First HTML | Pending branch | Pending branch, then the resolved branch in the same response |
| Where the promise resolves | In the browser, after hydration | On the server |
| Branch content | Any Svelte markup | Elements, {expressions} and {@html} only |
| Page hydration | Yes | No |
| Handler option | None | collectStreamingSlots: true |