You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This bug took me hours to understand and realize a minimum reproduction for, but it's currently blocking my company site from fully functioning.
This issue is seemingly related to #11057 (and maybe #13527/#13631), but it's not due to just "malformed HTML".
What happens is that hydration fails, with a JS error/crash, after the server-side rendered page has shown and client-side rendering has begun to take over, when combining 3 specific things:
A page has an {#await} block
The await block awaits data that is conditionally a promise or not (in loader: return { key: browser ? promiseVal : val };)
The {#await} block and it's {:then} block BOTH contain a component. (This one took a long time to realize)
This will all make much more sense in the reproduction section, but yea, this ends up as a pretty bad break, breaking the whole page, showing nothing but an empty background as the whole app's %sveltekit.body% section is wiped out, with an error in the browser's console.
The specific error is different depending on the contents of your await block, but for example the minimum reproduction shows: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'substring'). My production app, however, shows: Uncaught (in promise) DOMException: Node.appendChild: Cannot add children to a Comment.
Due to the nature of the bug being due to hydration, though, it only occurs on fresh-page loads or browser refreshes of the page. If you navigate to a page that meets these repro requirements, and the app has already been initialized/hydrated, then no error occurs.
Removing the conditional promise loading (if (browser)) fixes the issue, but that's not a workable solution for my company's application, as we rely on the server-side rendering for SEO and noscript fallback, but need the client-side rendering for the app-like client-side instant navigation and loading UIs.
The text was updated successfully, but these errors were encountered:
Describe the bug
This bug took me hours to understand and realize a minimum reproduction for, but it's currently blocking my company site from fully functioning.
This issue is seemingly related to #11057 (and maybe #13527/#13631), but it's not due to just "malformed HTML".
What happens is that hydration fails, with a JS error/crash, after the server-side rendered page has shown and client-side rendering has begun to take over, when combining 3 specific things:
{#await}
blockreturn { key: browser ? promiseVal : val };
){#await}
block and it's{:then}
block BOTH contain a component. (This one took a long time to realize)This will all make much more sense in the reproduction section, but yea, this ends up as a pretty bad break, breaking the whole page, showing nothing but an empty background as the whole app's
%sveltekit.body%
section is wiped out, with an error in the browser's console.The specific error is different depending on the contents of your await block, but for example the minimum reproduction shows:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'substring')
. My production app, however, shows:Uncaught (in promise) DOMException: Node.appendChild: Cannot add children to a Comment
.Due to the nature of the bug being due to hydration, though, it only occurs on fresh-page loads or browser refreshes of the page. If you navigate to a page that meets these repro requirements, and the app has already been initialized/hydrated, then no error occurs.
Reproduction
For full context, here's a full minimum reproduction on StackBlitz:
https://stackblitz.com/edit/sveltekit-conditional-promise-rendering-bug?file=src%2Froutes%2F%2Bpage.svelte
Otherwise, the important bits are:
+page.js
+page.svelte
Logs
(Shortened. Expand for full log...)
System Info
Severity
serious, but I can work around it
Additional Information
Removing the conditional promise loading (
if (browser)
) fixes the issue, but that's not a workable solution for my company's application, as we rely on the server-side rendering for SEO andnoscript
fallback, but need the client-side rendering for the app-like client-side instant navigation and loading UIs.The text was updated successfully, but these errors were encountered: