ctrlplusb / react-tree-walker

Walk a React (or Preact) element tree, executing a "visitor" function against each element.
MIT License
345 stars 34 forks source link

Could not handle instance-as-result from Stateless component #19

Closed theKashey closed 6 years ago

theKashey commented 6 years ago

Original issue - https://github.com/gaearon/react-hot-loader/issues/832 React-Hot-Loader is a bit hacky thing, and it's functional component wrapper will return an instance from render. This is a not common, but absolutely legit behavior, called IndeterminateComponent. Used by Relay as I know (https://github.com/facebook/relay/blob/d77a34c6b5abddfe078b0d50c2d43181fe35d574/packages/react-relay/classic/container/RelayContainer.js#L1050-L1055, dont know anyone else). Unfortunately react-tree-walker(React.Children.count, to be more correct) cannot stand this, throwing an error.

Example - https://codesandbox.io/s/6wz0or0rqk, or in original issue.

thien-do commented 6 years ago

@theKashey if you have time, please see #23 to see if it can help :D