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, closes #1189 (the alternative converter-level fix): 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 28, 2026 12:19pm

Request Review

@mrousavy

Copy link
Copy Markdown
Owner

Overall this PR is quite good and fixes a valid bug - thank you!

I will investigate a bit further to see if we can get the prop converter fully into Nitro core so that it's not a burden of the generated code to properly convert props. That includes the f unwrapping of functions, seems like there's more stuff we need to do to support Views than just unwrap props :)

@mfazekas
mfazekas force-pushed the fix/view-optional-prop-null-handling branch from 3bde52e to 1f0a6ed Compare July 28, 2026 12:19
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

2 participants