SIGN IN SIGN UP
facebook / react-native UNCLAIMED

A framework for building native applications using React

0 0 0 C++

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

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`:

https://github.com/user-attachments/assets/89752243-ff48-42c7-a584-b47a091b4a4d

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

Pull Request resolved: https://github.com/facebook/react-native/pull/56288

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

```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
```

2. run RNTester Playground on Android, and press `Toggle` to switch `zIndex` between `1` and `undefined`.

This is with the issue fixed:

https://github.com/user-attachments/assets/11253c23-b235-4e70-89a3-0d7bd07937f5

Reviewed By: javache

Differential Revision: D98960669

Pulled By: NickGerleman

fbshipit-source-id: d4a98434c599d2298c5cfc8c6895988ed0743af6
H
Hanno J. Gödecke committed
93b37350afe8db7b4835ba59f40ea1e55e4a3045
Parent: 5964a19
Committed by meta-codesync[bot] <215208954+meta-codesync[bot]@users.noreply.github.com> on 4/1/2026, 1:01:10 AM