Skip to content

Add null safety to RootComponentView() to prevent crash during island…#8

Open
gmacmaster wants to merge 1 commit intomainfrom
fix/root-component-view-null-safety
Open

Add null safety to RootComponentView() to prevent crash during island…#8
gmacmaster wants to merge 1 commit intomainfrom
fix/root-component-view-null-safety

Conversation

@gmacmaster
Copy link
Copy Markdown

No description provided.

… teardown

RootComponentView() dereferenced a weak_ref without null checking. Changed
return type from reference to pointer and added null guards at all 18
call sites to prevent crashes when pointer/keyboard events arrive after
the ReactNativeIsland is destroyed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 18, 2026

Greptile Summary

This PR adds null safety to RootComponentView() by changing its return type from a reference to a pointer and guarding every call site with a null check, preventing a crash when m_wkRootView has already been released (e.g. during island teardown). All 17 call sites in CompositionEventHandler.cpp and the header declaration are updated consistently.

Confidence Score: 5/5

Safe to merge — the fix is minimal, targeted, and all call sites are consistently guarded.

Every use of RootComponentView() is now null-checked before dereference. The change is mechanical and consistent across all 17 sites, with no new logic or regressions introduced. No custom rules are violated.

No files require special attention.

Important Files Changed

Filename Overview
vnext/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp Return type changed to pointer; all 17 call sites updated with null guards (early return / break) before any dereference — consistent and complete.
vnext/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.h Header declaration updated from reference to pointer return type, matching the implementation change.

Sequence Diagram

sequenceDiagram
    participant EH as CompositionEventHandler
    participant RCV as RootComponentView()
    participant Island as ReactNativeIsland (weak ref)
    participant RCVObj as RootComponentView object

    EH->>RCV: call RootComponentView()
    RCV->>Island: m_wkRootView.get() (promote weak ref)
    alt island is null (already released)
        RCV-->>EH: return nullptr
        EH-->>EH: early return / break (no crash)
    else island alive
        Island->>RCVObj: GetComponentView()
        RCVObj-->>RCV: raw pointer
        RCV-->>EH: return pointer
        EH->>RCVObj: dereference (GetFocusedComponent / hitTest / etc.)
    end
Loading

Reviews (1): Last reviewed commit: "Add null safety to RootComponentView() t..." | Re-trigger Greptile

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