Skip to content

Svelte 5: Displaying component-bound prop causes ERR_SVELTE_HYDRATION_MISMATCH #10426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ciscoheat opened this issue Feb 8, 2024 · 3 comments · Fixed by #10433
Closed

Svelte 5: Displaying component-bound prop causes ERR_SVELTE_HYDRATION_MISMATCH #10426

ciscoheat opened this issue Feb 8, 2024 · 3 comments · Fixed by #10433
Assignees
Labels
Milestone

Comments

@ciscoheat
Copy link

Describe the bug

When binding a prop to a component prop and displaying it in certain circumstances, in the browser there is a ERR_SVELTE_HYDRATION_MISMATCH error.

It varies quite a lot when it fails, so the repo gives the details in code.

Reproduction

https://github.com/ciscoheat/svelte5-bind-hydrate

Logs

ERR_SVELTE_HYDRATION_MISMATCH: Hydration failed because the initial UI does not match what was rendered on the server. TypeError: Cannot read properties of undefined (reading '__nodeValue')
    at text (render.js:444:30)
    at render.js:434:22
    at execute_signal_fn (runtime.js:360:6)
    at execute_effect (runtime.js:538:29)
    at schedule_effect (runtime.js:634:4)
    at internal_create_effect (runtime.js:1383:3)
    at render_effect (runtime.js:1513:9)
    at Module.text_effect (render.js:434:2)
    at +page.svelte:10:20
    at render.js:1523:5

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
    Memory: 44.00 GB / 63.93 GB
  Binaries:
    Node: 21.4.0 - C:\Program Files\nodejs\node.EXE       
    Yarn: 1.22.21 - ~\AppData\Local\pnpm\yarn.CMD
    npm: 9.3.1 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.15.1 - ~\AppData\Local\pnpm\pnpm.CMD
  Browsers:
    Edge: Chromium (121.0.2277.106)
    Internet Explorer: 11.0.19041.3636
  npmPackages:
    svelte: ^5.0.0-next.1 => 5.0.0-next.50

Severity

blocking an upgrade

@dummdidumm dummdidumm added this to the 5.0 milestone Feb 8, 2024
@ciscoheat
Copy link
Author

Added some more test cases to the repo.

@dummdidumm
Copy link
Member

dummdidumm commented Feb 8, 2024

The minimum reproducible is just {''} - the empty string cases problems (and [] is becoming the empty string).

Out of curiousity: This kind of binding pattern is likely an error in Svelte 5 runes mode (i.e. having a undefined value bound to a property with a fallback value). What's the use case for this, and can you work around it by just initializing the value in the parent?

@dummdidumm dummdidumm self-assigned this Feb 8, 2024
@dummdidumm dummdidumm added the bug label Feb 8, 2024
@ciscoheat
Copy link
Author

There's no special use case, I think I was copying a component from a failing test, and added some text. Didn't see that the initialization is backwards! I can certainly initialize it in the parent instead.

dummdidumm added a commit that referenced this issue Feb 8, 2024
When there's only a single expression tag and its value evaluates to the empty string, special handling is needed to create and insert a text node
fixes #10426
Rich-Harris added a commit that referenced this issue Feb 9, 2024
* fix: handle sole empty expression tags

When there's only a single expression tag and its value evaluates to the empty string, special handling is needed to create and insert a text node
fixes #10426

* fix

* need this, too

* Update packages/svelte/src/internal/client/operations.js

---------

Co-authored-by: Rich Harris <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants