Skip to content

2.0.0-beta.28: Hydration mismatch when using spread + ternary on an attribute + For #2959

Description

@dangkyokhoang

Describe the bug

The below pattern causes hydration mismatch:

const Icon: Component<any> = (props) => {
  const rest = omit(props, "iconNode");
  return (
    <svg {...rest} stroke-width={props.cond ? props.x : 2}>
      <For each={props.iconNode}>{([tag, attrs]) => <div />}</For>
    </svg>
  );
};
Hydration completed with 4 unclaimed server-rendered node(s):
  <div _hk="2100"></div>
  <div _hk="2110"></div>
  <div _hk="2120"></div>
  <div _hk="2130"></div>

For as a sibling also causes the issue:

const TextInput: Component<any> = (props) => {
  return (
    <>
      <input {...props} data-test={props.cond ? props.x : 2} />
      <For each={[1, 2]}>{() => <div />}</For>
    </>
  );
};

Your Example Website or App

https://stackblitz.com/edit/nitrojs-nitro-uqjyhazp?file=src%2Fapp.tsx

Steps to Reproduce the Bug or Issue

  1. Go to the link above
  2. See console logs

Expected behavior

No hydration issue

Screenshots or Videos

No response

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

Additional context

No response

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