Skip to content

[Bug?]: reading JSX.Element prop outside JSX or > 1 time causes SSR hydration mismatch errorsΒ #1993

Description

@illiaChaban

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

Hydration fails if you read element prop outside JSX like

const BrokenTest = (p: { children?: JSXElement }) => {
  console.log(p.children);
  return <div/>;
};

or more than once like p.children && <div>{p.children}</div> or <Show ...> equivalent

However, if you use a pipe or IIFE where underlying component reads the (jsx.element) signal only once inside template, it works.

Example:

(() => {
  const el = p.children;
  return  <div>{el && <div>{el}</div>}</div>
})()

or

{pipe(p.children, el => el && <div>{el}</div>}

I'm guessing SolidJs creates a hydration key on each read action and then fails to find it inside the DOM.

Another thing to note:

  • this seems to cause issues when passed children contains an html element (<div>hi</div>), but not if i just pass a string by itself

Expected behavior πŸ€”

hydration should work in all those cases

Steps to reproduce πŸ•Ή

stackblitz: https://codesandbox.io/p/devbox/423f4v

select any "not working" option and refresh the demo window -> see hydration error

Short example:

...
<Route href="/" component={() => <BrokenTest><div>boom</div></BrokenTest>} />
...

const BrokenTest = (p: { children?: JSXElement }) => {
  console.log(p.children);
  return <div/>;
}

// OR

const BrokenTest = (p: { children?: JSXElement }) => {
  return <div>{p.children && <div>{p.children}</div>}</div>
}

Context πŸ”¦

No response

Your environment 🌎

all latest:
    "@solidjs/meta": "^0.29.4",
    "@solidjs/router": "^0.15.3",
    "@solidjs/start": "^1.2.0",
    "solid-js": "^1.9.9",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions