Skip to content

fix(android): fix bad_optional_access when zIndex changes to undefined with props 2.0#56288

Closed
hannojg wants to merge 2 commits intofacebook:mainfrom
hannojg:fix/android-props20-zindex
Closed

fix(android): fix bad_optional_access when zIndex changes to undefined with props 2.0#56288
hannojg wants to merge 2 commits intofacebook:mainfrom
hannojg:fix/android-props20-zindex

Conversation

@hannojg
Copy link
Copy Markdown
Contributor

@hannojg hannojg commented Mar 31, 2026

Summary:

When Android props 2.0 diffs a View where zIndex changes from a value to undefined, HostPlatformViewProps::getDiffProps calls zIndex.value() and throws bad_optional_access:

Screen.Recording.2026-03-31.at.15.22.21.mov

This change emits folly::dynamic(nullptr) when zIndex is cleared instead.

Changelog:

[ANDROID] [FIXED] - Fixed a crash when clearing zIndex with props 2.0 enabled

Test Plan:

Use the repro in packages/rn-tester/js/examples/Playground/RNTesterPlayground.js:

function Playground() {
  const [toggle, setToggle] = React.useState(false);

  return (
    <View style={styles.container}>
      <Button title="Toggle" onPress={() => setToggle(t => !t)} />
      <View
        style={{
          backgroundColor: toggle ? 'blue' : 'red',
          height: 100,
          width: 100,
          position: 'absolute',
          zIndex: toggle ? undefined : 1,
        }}
      />
    </View>
  );
}
  1. Enable Android props 2.0:
  override fun enableAccumulatedUpdatesInRawPropsAndroid(): Boolean = true
  override fun enableExclusivePropsUpdateAndroid(): Boolean = true
  override fun enablePropsUpdateReconciliationAndroid(): Boolean = true
  1. run RNTester Playground on Android, and press Toggle to switch zIndex between 1 and undefined.

This is with the issue fixed:

Screen_recording_20260331_152017.mp4

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 31, 2026
hannojg added a commit to discord/react-native that referenced this pull request Mar 31, 2026
@hannojg hannojg changed the title fix(android): fix bad_optional_access when Index changes to undefined with props 2.0 fix(android): fix bad_optional_access when zIndex changes to undefined with props 2.0 Mar 31, 2026
@hannojg hannojg changed the title fix(android): fix bad_optional_access when zIndex changes to undefined with props 2.0 fix(android): fix bad_optional_access when zIndex changes to undefined with props 2.0 Mar 31, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Mar 31, 2026
…ew/platform/android/react/renderer/components/view/HostPlatformViewProps.cpp

Co-authored-by: Pieter De Baets <pieter.debaets@gmail.com>
@hannojg
Copy link
Copy Markdown
Contributor Author

hannojg commented Mar 31, 2026

I committed the suggestion, i just want to note that the previous syntax structure is the one that the codegen generator will output (and i tried to conform to that but i guess for the manual implemented props it doesn't have to match!)

@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented Mar 31, 2026

@NickGerleman has imported this pull request. If you are a Meta employee, you can view this in D98960669.

@meta-codesync meta-codesync Bot closed this in 93b3735 Apr 1, 2026
@react-native-bot
Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @hannojg in 93b3735

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Apr 1, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented Apr 1, 2026

@NickGerleman merged this pull request in 93b3735.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants