Skip to content

The result of a nested React.Children.map is not consistent with React.isValidElement #2286

@skvale

Description

@skvale

Something like:

const ProblemChild = ({ children }) => {
  return React.Children.map(children, child => {
    return React.Children.map(child.props.children, innerChild => {
      return innerChild;
    });
  }).filter(React.isValidElement)
};

const App = () => {
  return (
    <ProblemChild>
      <div>
        <div>
          1
        </div>
        <div>
          2
        </div>
      </div>
    </ProblemChild>
  )
};

returns

1
2

in React, but nothing in preact/compat.

It looks like the nested React.Children.map causes React.isValidElement to return false for the divs

reproduce with this repo: https://github.com/skvale/preact-react.children.map-issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    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