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

Fixing crash when passing null children to view with no-hide-descendents #13224

Merged

Conversation

slswalker
Copy link
Contributor

@slswalker slswalker commented May 13, 2024

Description

When passing null to the children prop of a view that uses importantForAccessibility="no-hide-descendents", React Native Windows JS code wil crash due to the assumption that in this case, the children must be nonnull. React allows null and undefined on the type ReactNode, which is the go to type for declaring the type for the children prop on a component.

This is most likely a rare combination of props, though it is still valid. React.Children.map() has the following type:
map<T, C>(children: C | readonly C[], fn: (child: C, index: number) => T): C extends null | undefined ? C : Exclude<T, boolean | null | undefined>[];
The fix proposed is to check for null or undefined before using React.Children.map().

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Why

This fixes a crash that my team in Xbox has encountered when upgrading our RNW version to 0.73 from 0.69. This is a pre-emptive fix as we caught this prior to check-in.

What

I've added defensive code to validate this codepath.

Screenshots

Add any relevant screen captures here from before or after your changes.

Testing

This is the fix we have in Xbox. Our testing is that it doesn't crash in this scenario anymore.

Changelog

yes if reasonable. This returns functionality that should be there.

"Fixed a crash that occurred when passing null to a View with "no-hide-descendents" set for importantForAccessibility.

Microsoft Reviewers: Open in CodeFlow

@slswalker slswalker requested a review from a team as a code owner May 13, 2024 16:27
@acoates-ms acoates-ms merged commit f636d2c into microsoft:main May 13, 2024
53 checks passed
acoates-ms added a commit to acoates-ms/react-native-windows that referenced this pull request May 14, 2024
…nts (microsoft#13224)

* Preventing crash when passing null children to view with no-hide-descendents

* Change files

---------

Co-authored-by: Sam Walker <sawalker@microsoft.com>
Co-authored-by: Andrew <30809111+acoates-ms@users.noreply.github.com>
acoates-ms added a commit that referenced this pull request May 14, 2024
* Cleanup the snapshots in E2E test app (#13229)

* Cleanup the snapshots

* format

* Process snapshots so that ImageSource Uri's are consistent

* Change files

* fix

* fix

* fix(TextInput/isFocused): correctly handle null focused input (#13219)

* Change files

* fix(TextInput/isFocused): correctly handle null focused input

Signed-off-by: Nathanael Bracy <nate@bracy.dev>

* fix

---------

Signed-off-by: Nathanael Bracy <nate@bracy.dev>
Co-authored-by: Andrew Coates <30809111+acoates-ms@users.noreply.github.com>

* Fixing crash when passing null children to view with no-hide-descendents (#13224)

* Preventing crash when passing null children to view with no-hide-descendents

* Change files

---------

Co-authored-by: Sam Walker <sawalker@microsoft.com>
Co-authored-by: Andrew <30809111+acoates-ms@users.noreply.github.com>

* C++20: use view() instead of str() to avoid a copy, use starts_with (#13218)

* Change files

* C++20: use view() instead of str() to avoid a copy, use starts_with

Signed-off-by: Nathanael Bracy <nate@bracy.dev>

* fix

* Apply changefile modifications from code review

Co-authored-by: Jon Thysell <thysell@gmail.com>

* Revert package.json

Signed-off-by: Nathanael Bracy <nate@bracy.dev>

---------

Signed-off-by: Nathanael Bracy <nate@bracy.dev>
Co-authored-by: Andrew Coates <30809111+acoates-ms@users.noreply.github.com>
Co-authored-by: Jon Thysell <thysell@gmail.com>

* ViewComponentView should be activatable from rn-win32.dll (#13225)

* ViewComponentView should be activatable from rn-win32.dll

* Change files

* Cleanup the snapshots in E2E test app (#13229)

* Cleanup the snapshots

* format

* Process snapshots so that ImageSource Uri's are consistent

* Change files

* fix

* fix

* lint

* format

* Revert "C++20: use view() instead of str() to avoid a copy, use starts_with (#13218)"

This reverts commit 71335b5.

---------

Signed-off-by: Nathanael Bracy <nate@bracy.dev>
Co-authored-by: Nate <37554478+servusdei2018@users.noreply.github.com>
Co-authored-by: Sam Walker <samuel.ls.walker@gmail.com>
Co-authored-by: Sam Walker <sawalker@microsoft.com>
Co-authored-by: Jon Thysell <thysell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants