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

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

Closed
danieldiekmeier opened this issue Nov 4, 2024 · 2 comments

Comments

@danieldiekmeier
Copy link

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
@mcous
Copy link
Collaborator

mcous commented Nov 4, 2024

Thanks for this report! It looks very similar to #319 - the cause of which was capricorn86/happy-dom#1392. If you have the time and ability, it would be super helpful if you could use the Svelte source code as a guide to narrow this reproduction down to a specific vanilla JS interaction that causes this exception in happy-dom.

They're super responsive to bugs over at happy-dom, so if we can figure out the specific interaction - without Svelte itself actually involved - I'm sure we can get it fixed quickly.

@danieldiekmeier
Copy link
Author

Thank you for the quick reply and the encouragement to dig deeper. I dug so far that I found out it that the bug is directly in happy-dom and not at all here, so I created a new issue over there. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants