Anyone playing with @astro 5.14 and async rendering for @sveltejs? I'm trying to do what I thought would be a basic thing, grabbing an entry from my content collection (`await getEntry(‘collection’, 'item’)`) in my script tag, but I'm getting `Cannot await outside a <svelte:boundary> with a pending snippet` as an error, and the error URL 404s.

@snugug @astro @sveltejs can you clarify what you mean by „in my script tag“?

async Svelte in Astro works pretty well so far. I’ve tested these constellations and for islands I wrote some lines here: https://fubits.dev/notes/svelte-5-patterns-async-remote/#updates

@fubits @astro @sveltejs I'm doing something like:

<script>
import {getEntry} from 'astro:content';

const item = await getEntry('collection', 'item');

</script>

Server render only, want to use item throughout the component. Syntax may be off, on phone.

@snugug @astro @sveltejs just to confirm - you are doing that in a *.astro file, right?

And if yes - where is the async Svelte component being imported?

@fubits @astro @sveltejs No, I'm doing it in a Svelte file, trying to use the new async Svelte rendering to grab the content
@fubits @astro @sveltejs It should be functionally identical to the included example in the 5.14 release notes (https://astro.build/blog/astro-5140/#async-rendering-support-for-svelte) and the Svelte 5 docs explicitly call out top-level `await` inside a component's <script> tag (https://svelte.dev/docs/svelte/await-expressions). I've got my `svelte.config.js` file set up correctly, but getting the error I shared (I know it's set up right because before I was getting top-level await not allowed without async rendering enabled)
Astro 5.14 | Astro

Astro 5.14 has a bumper harvest of features and DX improvements to warm the cockles of your heart, with new routing tools, async Svelte rendering, React 19 actions support, and more!

Astro

@snugug @astro @sveltejs that’s a conceptual problem, not an async Svelte one.

Svelte is a frontend framework. Astro is a meta-framework like SvelteKit / Next / Nuxt.
Astro‘s content API belongs in Astro-land.

Frontend in Astro lives in client islands (unless wrapped in Server Islands).

You can only pass entries to Svelte (maybe even as a Promise) as props/children.

And pre-rendering would be tricky.

There’s an experimental API tho https://docs.astro.build/en/reference/container-reference/

Astro Container API (experimental)

Docs
@fubits @astro @sveltejs Thanks for your feedback here, but, I'm not quite sure it aligns with my current problem. Even using browser built-ins with the async rendering (specifically, fetch, as demonstrated in the Astro 1.4 release notes) fails with the "cannot use `await`…" error, so there's something else going on here before being able to determine whether it's possible to use Astro content APIs in my server-only Svelte component.

@snugug @astro @sveltejs hm, here’s a working example with async fetch and different client directives https://fubits.dev/svelte-async-server-island/

What helped me grok the relationship between Astro and async Svelte was starting with a very minimal example in StackBlitz. Maybe you could create a reproducible example of your bug.

Test: async Svelte & SSR in Astro - @fubits

Full Stack Developer specializing in Svelte, SvelteKit, Data Visualization, and Technical Project Management for NGOs and startups

fubits Portfolio
@fubits @astro @sveltejs Thanks for the follow-up. I'd encourage you to take a look at the links I've shared—your examples are great for _some_ of the uses of async rendered Svelte, but do not actually show what I'm interested and should be possible: top-level await in a server-only component.

@fubits @astro @sveltejs For clarity, ignore my desire to use Astro Content APIs for a moment. I'd like to get the example from the Astro 5.14 changelog working as a server-only component.

https://astro.build/blog/astro-5140/#async-rendering-support-for-svelte:~:text=contributing%20this%20feature!-,Async%20rendering%20support%20for%20Svelte,-This%20release%20adds

Astro 5.14 | Astro

Astro 5.14 has a bumper harvest of features and DX improvements to warm the cockles of your heart, with new routing tools, async Svelte rendering, React 19 actions support, and more!

Astro

@snugug @astro @sveltejs I’m not sure if I understand by „server-only component“ but if you omit the boundary in Svelte and omit the client directive in Astro, the Svelte component will run at build time, pre-render and not hydrate on the client.

As in - the async-fetched joke example „without `svelte:boundary` + no client directive?“ further down here is static: https://fubits.dev/svelte-async-ssr/

Test: async Svelte & SSR in Astro - @fubits

Full Stack Developer specializing in Svelte, SvelteKit, Data Visualization, and Technical Project Management for NGOs and startups

fubits Portfolio

@fubits @astro @sveltejs Ok, great, this is what I'm looking for and can't replicate (getting a svelte boundary error). I'll look at this example and see what the difference is.

And yes, I understand it won't hydrate on the client side. I personally prefer Svelte's DSL for templating to JSX that Astro uses, so I write most of my non-hydrated components with Svelte.

@fubits @astro @sveltejs Ok, I think there must have been something wrong with the codebase I was testing in, this works as expected (even using getEntry from a Svelte component) in a clean repo. I'm curious as to how your sample app is working through; the async rendering for Astro should only be 5.14+ and yours is 5.13.10.

Either way, I've got it working now. Thanks for chatting!

@snugug @astro @sveltejs the commit for async SSR happened in 5.13.10.
5.14 was just the announcement https://bsky.app/profile/mk.gg/post/3lzl37my5ic2u
Matt Kane (@mk.gg)

That was easy! https://github.com/withastro/astro/pull/14430

Bluesky Social