Skip to content

fix: Fix clearing optional view props crashing with "Value is null"#1432

Open
mfazekas wants to merge 2 commits into
mrousavy:mainfrom
mfazekas:fix/view-optional-prop-null-handling
Open

fix: Fix clearing optional view props crashing with "Value is null"#1432
mfazekas wants to merge 2 commits into
mrousavy:mainfrom
mfazekas:fix/view-optional-prop-null-handling

Conversation

@mfazekas

@mfazekas mfazekas commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Fixes #1184. Alternative to #1189: instead of loosening JSIConverter<std::optional<T>> for all conversions, this maps null to "no value" only for view props - CachedProp::fromRawValue treats null like undefined, unless the prop's type explicitly models null (e.g. string | null). Method arguments and hybrid object properties stay strict about null vs undefined.

For view props that distinction doesn't exist anyway: React sends null both for a removed prop (ReactNativeAttributePayload.js#L390-L394) and for an explicit undefined (#L270-L277), so the native side cannot tell them apart - it just crashed the commit with Exception in HostFunction: <View>.<prop>: Value is null, expected a String.

Also covers optional callback props (not fixed by #1189): those crashed earlier, in the generated { f: ... } unwrap (value.asObject()), before any converter ran.

Notes:

  • For props that model null (foo?: string | null), clearing the prop delivers null, not undefined - React's payload makes the two indistinguishable, and null-modeling types take null at face value. Pinned by a test.
  • Required props are untouched: a null payload still throws, with the original "Value is null" message.
  • The callback-prop part lives in generated code, so libraries pick it up by re-running nitrogen; the CachedProp part ships with react-native-nitro-modules directly.

Tests: optional props on the existing TestView + on-device harness tests in example/__tests__/views.harness.tsx (clearing a prop needs React's commit path, so this can't live in getTests.ts). They fail on main (#1433) and pass here, verified on iOS and Android.

Checklist

@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
nitro-docs Skipped Skipped Jul 8, 2026 1:51pm

Request Review

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.

Error when assigning undefined to optional view property

1 participant