Skip to content
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

TypeError: next_sibling is null during hydration #14405

Closed
jrmajor opened this issue Nov 23, 2024 · 4 comments · Fixed by #14425
Closed

TypeError: next_sibling is null during hydration #14405

jrmajor opened this issue Nov 23, 2024 · 4 comments · Fixed by #14425
Assignees
Labels

Comments

@jrmajor
Copy link
Contributor

jrmajor commented Nov 23, 2024

Describe the bug

When certain component is SSR-ed, I get a type error during hydration (see logs section). Minimal reproduction I could make looks like this:

<script>
	let { name, remaining } = $props();
</script>

<span>
	<span>{name}</span>{remaining >= 2 ? ',' : ''}
</span>

The problem is caused by spacing between </span> and {. When I make the following change, the error no longer occurs:

- <span>{name}</span>{remaining >= 2 ? ',' : ''}
+ <span>{name}</span> {remaining >= 2 ? ',' : ''}

This crash causes Svelte to remove everything from DOM. Page that was server rendered not only isn't hydrated, but just goes blank.

Reproduction

Failing test: https://github.com/jrmajor/svelte/tree/c659c94d16a7306848935ff4ed11a4b4bb091873/packages/svelte/tests/hydration/samples/strange-spacing
Commit with tests to cherry pick: jrmajor@c659c94

screenshot-2024-11-23T09 21 26@2x

Logs

Uncaught (in promise) TypeError: can't access property "nodeType", next_sibling is null

  in MainCredits.svelte
  in Show.svelte
  in Render.svelte
  in Layout.svelte
  in Render.svelte
  in App.svelte
    sibling operations.js:166
    ArtistName ArtistName.svelte:74
    effect2 hmr.js:47
    update_reaction runtime.js:318
    update_effect runtime.js:444
    create_effect effects.js:125
    branch effects.js:346
    wrapper hmr.js:38
    update_reaction runtime.js:318
    update_effect runtime.js:444

System Info

System:
  OS: macOS 15.0
  CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Memory: 514.17 MB / 16.00 GB
  Shell: 3.7.1 - /usr/local/bin/fish
Binaries:
  Node: 23.1.0 - /usr/local/bin/node
  Yarn: 1.22.22 - /usr/local/bin/yarn
  npm: 10.9.0 - /usr/local/bin/npm
  pnpm: 9.12.3 - /usr/local/bin/pnpm
  bun: 1.1.34 - /usr/local/bin/bun
Browsers:
  Safari: 18.0
npmPackages:
  svelte: ^5.2 => 5.2.0

Severity

blocking all usage of svelte

@jrmajor jrmajor changed the title TypeError: next_sibling is null in SSR TypeError: next_sibling is null during hydration Nov 23, 2024
@trueadm trueadm self-assigned this Nov 25, 2024
@trueadm trueadm added the bug label Nov 25, 2024
@jrmajor
Copy link
Contributor Author

jrmajor commented Jan 1, 2025

Thank you for fixing that, @trueadm. Can something be done to prevent similar errors from nuking the entire page in the future? One of the benefits from SSR is that even if JS fails, the HTML can still be displayed correctly. That error caused the entire DOM to be destroyed, leaving user with a blank page, even though the HTML was SSR-ed.

@kewp
Copy link

kewp commented Feb 19, 2025

I'm getting a similar error on my app ... not sure how to debug it?

Uncaught (in promise) TypeError: Unhandled Promise Rejection: node is null
    remove_nodes hydration.js:90
    update_branch if.js:60
    if_block if.js:104
    update_reaction runtime.js:424
    update_effect runtime.js:578
    create_effect effects.js:125
    block effects.js:361

Using svelte 5.20.2

@trueadm
Copy link
Contributor

trueadm commented Feb 19, 2025

I'm getting a similar error on my app ... not sure how to debug it?

Uncaught (in promise) TypeError: Unhandled Promise Rejection: node is null
    remove_nodes hydration.js:90
    update_branch if.js:60
    if_block if.js:104
    update_reaction runtime.js:424
    update_effect runtime.js:578
    create_effect effects.js:125
    block effects.js:361

Using svelte 5.20.2

Can you create a new issue, and maybe provide a repro or link to your code? A stack trace doesn't really help here.

@kewp
Copy link

kewp commented Feb 20, 2025

I can't figure out what caused it, so don't know how to make a minimal example...

However turning on preserve whitespace fixed it:

compilerOptions: {
		preserveWhitespace: true
	},

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.

3 participants