Skip to content

Svelte 5: {@html someVar} Does not hydrate after SSR #12333

Closed
@happycollision

Description

@happycollision

Describe the bug

Using {@html someVar} in Svelte 5, I noticed that hydration does not overwrite the SSR value. For example (and this is in the reproduction repo), consider this component in a SvelteKit app:

<script>
	import { browser } from "$app/environment"
	const renderLocation = browser ? "In browser" : "On server"
</script>

<h1>Welcome to SvelteKit</h1>

Standard: {renderLocation}
<br />
@html: {@html renderLocation}

I would expect that after hydration, the page would say:

<h1>Welcome to SvelteKit</h1>

Standard: In browser
<br />
@html: In browser

But instead, it says:

<h1>Welcome to SvelteKit</h1>

Standard: In browser
<br />
@html: On server

Reproduction

https://github.com/happycollision/svelte-hydration-issue

  1. Clone the repo.
  2. There are two folders, svelte5 and svelte4. In both, you should pnpm i.
  3. Do npm run dev in one, check the output of the root route.
  4. Do the same in the other and see that it is different.

In the svelte 4 version, you'll see this:

CleanShot 2024-07-07 at 17 03 51@2x

In the svelte 5 version, you'll see this:

CleanShot 2024-07-07 at 17 03 23@2x

NOTE: There are no runes in use in the Svelte 5 version.

Logs

No response

System Info (svelte4)

System:
    OS: macOS 14.4.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 1.93 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.asdf/installs/nodejs/20.10.0/bin/node
    npm: 10.2.3 - ~/.asdf/plugins/nodejs/shims/npm
    pnpm: 9.0.6 - ~/.asdf/installs/nodejs/20.10.0/.npm/bin/pnpm
    bun: 1.0.3 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 126.1.67.123
    Safari: 17.4.1
  npmPackages:
    svelte: ^4.2.7 => 4.2.18

System Info (svelte5)

  System:
    OS: macOS 14.4.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 1.11 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.asdf/installs/nodejs/20.10.0/bin/node
    npm: 10.2.3 - ~/.asdf/plugins/nodejs/shims/npm
    pnpm: 9.0.6 - ~/.asdf/installs/nodejs/20.10.0/.npm/bin/pnpm
    bun: 1.0.3 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 126.1.67.123
    Safari: 17.4.1
  npmPackages:
    svelte: ^5.0.0-next.1 => 5.0.0-next.175 

Severity

blocking an upgrade

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions