kit icon indicating copy to clipboard operation
kit copied to clipboard

Contents of div containing %sveltekit.body% no longer replaced in SvelteKit 2.5.5

Open theodorejb opened this issue 1 year ago • 4 comments

Describe the bug

I have an SPA mode app using adapter-static.

My app.html file contains the following inside the <body> tag:

<div style="display: contents">
    <div class="loading-animation">
        <div></div>
        <div></div>
    </div>
    %sveltekit.body%
</div>

Up to SvelteKit 2.5.4, the loading-animation div was removed from the DOM when the SvelteKit app finishes loading. However, this no longer works in SvelteKit 2.5.5, and the loading animation continues to display on top of the loaded app.

Reproduction

My top-level +layout.ts file contains:

export const ssr = false;
export const prerender = false;

Logs

No response

System Info

Windows 11, Firefox 124

Severity

blocking an upgrade

Additional Information

I suspect this issue may be caused by https://github.com/sveltejs/kit/pull/12050.

theodorejb avatar Apr 09 '24 14:04 theodorejb

I think this is the right behaviour since no SSR means no hydration, thus no repairing the DOM. It's easy enough to query the document for the loading element and remove it in an onMount callback.

cc: @Rich-Harris was disabling the hydration behaviour on SPA project considered a breaking change?

teemingc avatar Apr 10 '24 03:04 teemingc

Isn't the Svelte app hydrated to the DOM regardless of whether SSR is enabled? To me it's confusing that siblings of %sveltekit.body% wouldn't always be replaced when it's rendered, especially given that this has always worked before. If this difference is intended, it should at least be documented somewhere.

theodorejb avatar Apr 12 '24 12:04 theodorejb

Isn't the Svelte app hydrated to the DOM regardless of whether SSR is enabled?

Hydration is only required when the page contents have already been rendered by SSR. If the HTML hasn't been rendered yet, it's just client-side rendering.

To me it's confusing that siblings of %sveltekit.body% wouldn't always be replaced when it's rendered, especially given that this has always worked before. If this difference is intended, it should at least be documented somewhere.

Yeah, this makes me think it might have been a breaking change and may be something we need to wait until the next major version for including documentation for it.

teemingc avatar Apr 12 '24 12:04 teemingc

This is still an issue in the latest version of SvelteKit. It would be good to have a final decision if this is a bug which will be fixed, or intended behavior (anyone with an SPA-mode app needs to manually remove DOM siblings of %sveltekit.body%).

theodorejb avatar Jun 11 '24 22:06 theodorejb

+1 for this feature

lemmon avatar Nov 19 '24 10:11 lemmon