Skip to content

Svelte 5: <noscript> breaks hydration #9952

@tombl

Description

@tombl

Describe the bug

When generating the client-side code, <noscript> elements are completely stripped out of the template.

This means that the server generates the elements, but the client acts as if they were never there. At best, this throws a hydration error, and at worst the wrong nodes are updated.

I've got a PR that solves this by turning <noscript> into a comment node in the client template.

Reproduction

REPL

<script>
  import { onMount } from "svelte";
  let count = 0;
  onMount(() => count++);
</script>
<noscript>JavaScript is required for this site.</noscript>
<h1>Hello!</h1>
<p>Count: {count}</p>

Results in <h1>Count: 1</h1> <p>Count: 0</p> hydrated to the DOM.
In Svelte 4 this renders fine.

Logs

No response

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.4.2 - /usr/local/bin/npm
    pnpm: 8.10.5 - /usr/local/bin/pnpm
  npmPackages:
    svelte: 5.0.0-next.26 => 5.0.0-next.26

Severity

blocking an upgrade

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions