Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**Problem:** See #6066 **Fix:** The major contributor to the slowness of `isElementInChildrenOrPropsTree ` is `React.children.toArray`. I tried to use `React.children.forEach` or `React.children.map` but those just made things worse. However, we know that in lot of cases `props.children` is just an array of elements or a React element itself. In these cases there is no need to run the fully general and slow toArray. Even though this is not the official use of the API (it is actually discouraged: https://react.dev/reference/react/Children#why-is-the-children-prop-not-always-an-array), it makes sense to try to get the elements without calling toArray (and we can still call `toArray` when that fails). I made the function even more faster by switching to simple `for` loops instead of using array functions and allocating even more arrays. With these changes I never saw >1.3ms shouldUpdate times when resizing a PromiseCard. **Manual Tests:** I hereby swear that: - [x] I opened a hydrogen project and it loaded - [x] I could navigate to various routes in Preview mode Fixes #6066
- Loading branch information