-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support for <svelte:boundary> on SSR / static generation (POC) #15462
base: main
Are you sure you want to change the base?
Conversation
|
|
I'm still unsure about this strategy, as it won't scale for the case where you don't have a <script>
let error = $state();
</script>
<Header error={error} />
<Form>
<svelte:boundary onerror={e => error = e}>
<ComponentThatErrors />
</svelte:boundary>
</Form> Not to mention this approach will likely break in the future if we ever plan on streaming the SSR HTML payload. |
Actually this won't work with SSR, because an error will cause an HTTP 500 and the page will not be rendered at all ! With this PR in case of error the SSR will skip the svelte:boundary children with no replacement since there is no For streaming, I have never done this, but it may be possible to "pause" the streaming to process this. No ? |
Hi, I made a small example here to show the error with the current version : https://github.com/adiguba/boundary-demo Switch to this PR with |
@adiguba For me, the fact that no other framework seems to render error boundaries on the server and yet don't suffer issues means that maybe we're missing an API on the server that is unrelated to error boundaries? |
This feels a little dangerous to me. The fact that we can't invoke It might not feel totally ideal to 500 the entire page if it would have been possible to serve mostly-functional HTML instead, but I'd definitely prefer it to this, I think. |
What's about a way to capture all => |
I just made a PoC for #15370
Currently
<svelte:boundary>
works like a simple block in SSR, and any errors on the children will generate an HTTP 500 error.So there is no way to handle template errors server side.
With this PR, if an error occur while rendering the children, it will be removed from the generated code and replaced by the
failed()
snippets (if any).Example, this code :
generate a SSR code like that :
=> failed() is ignored, and it just print the payload of the body without handling errors :(
With this PR, the generated code will be :
The boundary function will handle errors, and the payload will be populated as expected.
On hydration, the client will detect the error on SSR and drop the content in order to retry to rendering the template.
There is however a special case for
{@const}
, that can still generate an HTTP 500 if an error occurs on a{@const}
used or declared before another{@const}
used by the failed() snippets.Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.packages/svelte/src
, add a changeset (npx changeset
).Tests and linting
pnpm test
and lint the project withpnpm lint