Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#15332) use toArray or checks for mapping children #15333

Merged
merged 5 commits into from
Dec 6, 2023

Conversation

dabrad26
Copy link
Member

@dabrad26 dabrad26 commented Dec 6, 2023

Closes #15332

Using toArray to get rid of null or other non element children. See ticket for more info on how this was changed recently and the benefit of toArray over direct map.

@dabrad26 dabrad26 requested a review from a team as a code owner December 6, 2023 04:03
@dabrad26 dabrad26 changed the title fix(#15332) use toArray for mapping children [Switcher]: fix(#15332) use toArray for mapping children Dec 6, 2023
Copy link

netlify bot commented Dec 6, 2023

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 98835e3
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/656ffbf20f2dc700088f715f
😎 Deploy Preview https://deploy-preview-15333--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@dabrad26
Copy link
Member Author

dabrad26 commented Dec 6, 2023

I went through and quickly checked all uses of Children.map (https://github.com/search?q=repo%3Acarbon-design-system%2Fcarbon%20React.Children.map&type=code)

Quickly looking over each most had checks to validate that children were either Nodes or they had no dangerous code (calling on NULL or cloning). I did find two possible risks with ContentSwitcher and ProgressIndicator and have added them to this PR.

@dabrad26 dabrad26 changed the title [Switcher]: fix(#15332) use toArray for mapping children fix(#15332) use toArray or checks for mapping children Dec 6, 2023
@@ -56,6 +56,10 @@ function ProgressIndicator({
return (
<ul className={className} {...rest}>
{React.Children.map(children, (child, index) => {
if (!React.isValidElement(child)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be written in a few different ways; but I wanted to make as minimal impact; since bottom of this loop returns null I am just adding this one check for valid Element here instead of on each of the index checks below.

Copy link
Contributor

@guidari guidari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀

Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for putting up this fix! Sorry we didn't catch this in the initial PR #14989 😓

I personally find it super difficult to review file changes from .js to .tsx when the git diff splits the file into two separate changes like it did in that PR. If it would've been a unified diff we might've spotted this.

Sorry again for any inconvenience you had from this. Can we cut a new release for this once it's in @guidari @alisonjoseph?

@tay1orjones tay1orjones merged commit 450fdd7 into carbon-design-system:main Dec 6, 2023
20 checks passed
@tay1orjones
Copy link
Member

Actually we're slated to release 11.45.0 tomorrow, this should go out with that 👍

@dabrad26 dabrad26 deleted the 15332 branch December 6, 2023 16:54
@dabrad26
Copy link
Member Author

dabrad26 commented Dec 6, 2023

Thanks so much everyone for the quick release. Yeah. Typescript migrations are tough. We have done several over the years. So happy to help if you ever want to assign a typescript migration PR to me. :)

We could also look to expand unit tests for anything dealing with children to test all possible children (string nodes, null, elements) and that should help.

For us our unit tests caught this regression since I didn’t check a Header Bar Search button which returns a null initially.

@carbon-automation
Copy link
Contributor

Hey there! v11.45.0 was just released that references this issue/PR.

@tay1orjones
Copy link
Member

happy to help if you ever want to assign a typescript migration PR to me. :)

@dabrad26 That would be such a great help, thanks for offering!

danoro96 pushed a commit to danoro96/carbon that referenced this pull request Jan 18, 2024
…ldren (carbon-design-system#15333)

* fix(carbon-design-system#15332) use toArray for mapping children

* fix: Content switcher

* fix: progress indicator

* fix: typescript rules for ReactElement usage

* fix: format diff test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Switcher Throws with NULL children
3 participants