Skip to content

happy-dom can't render Svelte 5 component if it starts with an if block followed by a table with dynamic content #407

@danieldiekmeier

Description

@danieldiekmeier

It seems like I ran into a very specific edge case. I can't render a component that

  • starts with an if block
  • followed by a table that contains any kind of "dynamic" content

For example, this does not render. (Yes, it even happens with these "static dynamic" values.)

{#if true}
  <div>Hello</div>
{/if}

<table>
  <tbody>
    <tr>
      <td>{"Dynamic Fails"}</td>
    </tr>
  </tbody>
</table>

I'm getting this error:

TypeError: Cannot read properties of null (reading 'Symbol(nodeArray)')
 ❯ get firstChild node_modules/.pnpm/[email protected]/node_modules/happy-dom/src/nodes/node/Node.ts:272:25
 ❯ get_first_child node_modules/.pnpm/[email protected]/node_modules/svelte/src/internal/client/dom/operations.js:85:28
     83|  * @returns {Node | null}
     84|  */
     85| /*@__NO_SIDE_EFFECTS__*/
       |                            ^
     86| export function get_next_sibling(node) {
     87|  return next_sibling_getter.call(node);
 ❯ Module.child node_modules/.pnpm/[email protected]/node_modules/svelte/src/internal/client/dom/operations.js:109:10
 ❯ Repro src/Repro.svelte:37:33
 ❯ node_modules/.pnpm/[email protected]/node_modules/svelte/src/internal/client/render.js:230:16
 ❯ update_reaction node_modules/.pnpm/[email protected]/node_modules/svelte/src/internal/client/runtime.js:327:56
 ❯ Module.update_effect node_modules/.pnpm/[email protected]/node_modules/svelte/src/internal/client/runtime.js:455:18
 ❯ create_effect node_modules/.pnpm/[email protected]/node_modules/svelte/src/internal/client/reactivity/effects.js:98:26
 ❯ Module.branch node_modules/.pnpm/[email protected]/node_modules/svelte/src/internal/client/reactivity/effects.js:331:9
 ❯ node_modules/.pnpm/[email protected]/node_modules/svelte/src/internal/client/render.js:212:25

I have created a full reproduction here: https://github.com/danieldiekmeier/happy-dom-svelte5-repro

It even contains additional cases where you can see that if

  1. The table is completely static, it works
  2. Without the leading if block, it works
  3. With a div instead of a table, it works
System:
  OS: macOS 15.0.1
  CPU: (10) arm64 Apple M1 Max
  Memory: 10.10 GB / 64.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 22.11.0 - ~/.local/share/mise/installs/node/22/bin/node
  npm: 10.9.0 - ~/.local/share/mise/installs/node/22/bin/npm
  pnpm: 9.12.3 - ~/.local/share/mise/installs/node/22/bin/pnpm
npmPackages:
  @sveltejs/vite-plugin-svelte: ^4.0.0 => 4.0.0
  @testing-library/jest-dom: ^6.6.3 => 6.6.3
  happy-dom: ^15.8.3 => 15.8.3
  svelte: 5 => 5.1.9
  vitest: ^2.1.4 => 2.1.4

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