-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
{#await}
with a null-ish expression renders fullfiled branch during SSR
#9323
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
Comments
This works as intended. Svelte (not SvelteKit) short-circuits to the resolved state if it detects that the value is not a promise. Your second workaround is what I would use here (you could also do |
Hmm, I had a hunch this might be intentional, given that this behavior makes perfect sense in CSR-mode. I personally feel like always rendering the pending-branch during SSR (even if the value is not a promise) would be a better default behavior with less footguns. I'll look into adjusting the documentation to be less misleading :) Side-note: |
This is a documentation issue then |
…e fullfilled branch Fixes sveltejs#9323
…e fullfilled branch (sveltejs#9324) Fixes sveltejs#9323
Describe the bug
Unfortunately some libraries (in my case monaco-editor) do not play well with SSR. I followed the advice from the FAQ on How do I use a client-side only library?, opting to wrap using the client-only shenanigans in an
{#await}
-block to support a nice loading indicator:Note that the real-world
doClientOnlyShenanigans
involves a variety of nasty things, like dynamically importing modules with side-effects.This approach works, but has one subtle problem: during SSR
clientOnlyPromise
will remainundefined
.For some reason this short-circuits the
{#await}
-block into the fulfilled branch, even though the documentation on{#await}
explicitly states that only the pending state will be rendered during SSR.In this basic example this causes a flash of "undefined" on the page before hydration, but in real world applications this can cause much more severe issues like nauseating layout shifts.
Reproduction
Minimal reproduction
Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
I have found two workarounds for this issue:
{#await}
block in an{#if}
that checks ifclientOnlyPromise
is truthy.This is already strange, less-readable and unintuitive markup, but this also renders nothing during SSR. Instead of a friendly loading indicator the client will be welcomed with layout shifts during hydration.
You could duplicate the loading indicator in an
{:else}
branch, but this would lead to even hairier markup with an extra spinkle of code duplication.This is a little odd, but with a nice explanatory comment above this doesn't cause too much further headache.
The text was updated successfully, but these errors were encountered: