Closed c9r closed 1 week ago
@bluwy do we need to do something to suppose Svelte snippets?
Yeah the issue proposed solution seems fine to me. I'm pretty sure I've fixed this before (https://github.com/withastro/astro/pull/9285) but Svelte might've changed the implementation again.
Svelte 5 in RC from Apr 30 2024 any merged for this fix?
@bluwy - any ETA on this? 😅 Named slots don't work in Svelte 5 either, the same bug occurs
I am also running into the same issue.
up this issue
PRs are welcome, and OP is willing to send a PR
This should be fixed by https://github.com/withastro/astro/pull/12328
Fixed in @astrojs/svelte
5.7.3
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
When statically generating (or server-side rendering) a
.astro
page that contains a Svelte 5.0.0-next.80 component, static children of the Astro instantiation don't statically render as snippets in the Svelte component. Below is a minimal example, followed by a likely root cause, and a potential fix.Distilled example
Given the following Svelte 5 component, in
button.svelte
:included from an Astro component,
page.astro
:the following static HTML gets rendered (note the absence of a "Click Me!" child text node):
Root cause
Take a look at the JS output for the aforementioned
button.svelte
component (playground link):Note that, in the compiled Svelte 5 component above, the
children
snippet gets invoked as a side-effecting function with a$$payload
parameter.But if you look at
server-v5.js
, the bridged snippet functions created byrenderToStaticMarkup
simply return the interpolated Astro slots, rather than appending the rendered output to$$payload.out
(as appears to be the expectation, from a quick poke around the Svelte 5 codebase). Because the return value of the snippet function is unused by the compiled version of the Svelte component (at least as of v5.0.0-next.80), the child content of the Astro instantiation of the Svelte component simply gets discarded.server-v5.js#L25-28
Potential fix
Modifying the snippet functions generated by
renderToStaticMarkup
inserver-v5.js
to append their output to$$payload.out
, instead of returning it, leads to proper static rendering of the above button example.server-v5.js
What's the expected result?
Svelte 5 components should statically render children passed to them from Astro component instantiations. Note that the expected output includes the "Click Me!" text node that is absent from the currently generated output.
expected output
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-rw1mr4
Participation