Skip to content

fix: don't throw when an optional RiveView prop is cleared back to undefined#326

Open
mfazekas wants to merge 2 commits into
feat/rive-ios-experimentalfrom
fix/optional-prop-clear-null
Open

fix: don't throw when an optional RiveView prop is cleared back to undefined#326
mfazekas wants to merge 2 commits into
feat/rive-ios-experimentalfrom
fix/optional-prop-clear-null

Conversation

@mfazekas

@mfazekas mfazekas commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Setting an optional RiveView prop back to undefined (e.g. artboardName from a string to no value) threw Exception in HostFunction: RiveView.artboardName: Value is null, expected a String during React commit. Fabric's prop diff sends null (not undefined) when a prop is removed, and Nitro's JSIConverter<std::optional<T>> only maps undefined to nullopt, so the inner converter throws. This affects all seven optional props (artboardName, stateMachineName, autoPlay, alignment, fit, layoutScaleFactor, dataBind) and both Android backends — the generated prop parser is shared C++, so iOS is affected the same way.

The fix extends scripts/nitrogen-postprocess.ts to patch the generated HybridRiveViewComponent.cpp, treating null like undefined at the optional-prop parse sites. This is a workaround until it's fixed upstream in Nitro (mrousavy/nitro#1184, open fix PR mrousavy/nitro#1189); the postprocess step already runs as part of yarn nitrogen, so regeneration keeps the fix.

Includes a reproducer page (example/src/reproducers/OptionalPropClear.tsx) that sets each optional prop and then clears it: it failed 7/7 before the fix and passes 7/7 after, verified on the Android emulator with both the new and the legacy (USE_RIVE_LEGACY=true) backend.

mfazekas added 2 commits July 7, 2026 22:34
…defined

Fabric's prop diff sends null (not undefined) when a prop is removed, but
Nitro's JSIConverter<std::optional<T>> only maps undefined to nullopt, so
clearing any optional RiveView prop (artboardName, stateMachineName,
autoPlay, alignment, fit, layoutScaleFactor, dataBind) threw e.g.
"Exception in HostFunction: RiveView.artboardName: Value is null,
expected a String" during commit. Affects both backends and both
platforms since the generated prop parser is shared.

Post-process the nitrogen output to treat null like undefined for
optional props until mrousavy/nitro#1184 is
fixed upstream. Adds an Optional Prop Clear reproducer page that sets
and clears each optional prop (fails 7/7 unfixed, passes fixed on both
Android backends).
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.

1 participant