Skip to content

Can we make the ERR_SVELTE_HYDRATION_MISMATCH error more user friendly? #10630

Closed
@thebjorn

Description

@thebjorn

Describe the problem

I was getting this error

(index):57 ERR_SVELTE_HYDRATION_MISMATCH: Hydration failed because the initial UI does not match what was rendered on the server.

on a page that I eventually reduced to (it was example code from Auth.js):

<script>
    import LogOut from "$lib/components/LogOut.svelte";
    let { 
        data 
    } = $props();
</script>
<p>
    {#if data.session}
        <LogOut></LogOut>
    {/if}
</p>

and LogOut.svelte was simply

<h1>hello</h1>

In addition it only happened when the user was logged in (i.e. data.session) had a value.

It took me quite some time to figure out that it was the <p> and <h1> tags that were clashing - changing p to div, or h1 to strong solves the issue.

Quite obvious when you "get" it, but there wasn't any help from "the system" in figuring it out...

Describe the proposed solution

Would it be possible to include "what was rendered on the server", what "the initial UI" was, and/or where they didn't match?

Importance

would make my life easier

Metadata

Metadata

Assignees

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