Skip to content

Fix addViewAt crash on a ViewState with no view - #58527

Open
wneel wants to merge 1 commit into
react:mainfrom
wneel:fix/addviewat-null-view-soft-exception
Open

wneel wants to merge 1 commit into
react:mainfrom
wneel:fix/addviewat-null-view-soft-exception

Conversation

@wneel

@wneel wneel commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #58526.

SurfaceMountingManager.addViewAt calls checkNotNull(view) on a ViewState whose view can
legitimately be null, which throws and tears the surface down. A ViewState has no Android View in
two cases: createViewUnsafe only creates one when the node is layoutable, and updateEventEmitter
registers a bare placeholder via getOrPut for a tag it has never seen.

In production (#58526) it is the second case. The reported string
ViewState [3548] - isRoot: false - props: null - viewManager: null has props: null, which only
the updateEventEmitter placeholder can produce, since createViewUnsafe always assigns
currentProps before registering, and the root ViewState prints isRoot: true.

Either way the mount instruction stream is inconsistent, and this function already has an
established answer for that: the branch immediately above logs a soft exception and returns when the
ViewState is missing entirely. This makes the null-view case behave the same way, so a missing
Create degrades to a dropped insert rather than a dead surface. Same approach as #56389 and #57181
took for their branches.

Changelog:

[ANDROID] [FIXED] - Stop SurfaceMountingManager.addViewAt from crashing on a ViewState with no view

Test Plan

Added addViewAt_doesNotThrowWhenViewStateHasNoView to the existing
SurfaceMountingManagerTest. It preallocates a tag with isLayoutable = false, so a ViewState is
registered with no Android View, then calls addViewAt on it. Fails on main with
IllegalStateException: Unable to find view for viewState ... and tag 42, passes with this change.

No native code and no EventEmitterWrapper needed, so it runs under Robolectric like the rest of
the file. The neighbouring deleteView_isIdempotent test already relies on a soft exception not
throwing in this setup.

SurfaceMountingManager.addViewAt called checkNotNull(view) on a ViewState whose
view can legitimately be null, which threw and tore down the whole surface.
A ViewState has no Android View in two cases: createViewUnsafe only creates one
when the node is layoutable, and updateEventEmitter registers a bare placeholder
via getOrPut for a tag it has never seen.

Log a soft exception and skip the insert instead, matching the missing-viewState
branch immediately above it.

Fixes react#58526.
@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 Sep 14, 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 Sep 14, 2026
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. 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.

[Android][Fabric] addViewAt hard-crashes on a placeholder ViewState synthesised by updateEventEmitter

1 participant