Skip to content

Initialize UIManagerBinding::currentEventPriority_ to Default - #60174

Open
biitran0204-spec wants to merge 1 commit into
react:mainfrom
biitran0204-spec:fix-uimanagerbinding-event-priority-init
Open

biitran0204-spec wants to merge 1 commit into
react:mainfrom
biitran0204-spec:fix-uimanagerbinding-event-priority-init

Conversation

@biitran0204-spec

Copy link
Copy Markdown

Summary:

UIManagerBinding::currentEventPriority_ has no initializer, and the constructor (UIManagerBinding(std::shared_ptr<UIManager>)) doesn't set it. The field is only written inside dispatchEvent. Until the first native event is dispatched, nativeFabricUIManager.unstable_getCurrentEventPriority() returns whatever was in that memory.

React's Fabric renderer reads it in resolveUpdatePriority() when AppRegistry.runApplication calls updateContainer. So the app's first render gets an arbitrary lane:

  • Values that match no priority fall back to DefaultEventPriority, as expected.
  • A value of 1 gives DiscreteEventPriority, a sync render.
  • A value of 3 gives IdleEventPriority. React then renders the whole first pass in time slices on IdleLane, which never expires, and promise callbacks started during that render run before it commits.

How we found it. In an Expo app (RN 0.86.3, New Architecture, Android emulator), we logged fabricGetCurrentEventPriority() and the lane inside updateContainer:

  • Across launches, the priority read 1702129263 on some and 0 on others.
  • About 1 launch in 10 to 40 gave lane 268435456 (IdleLane) for the root's first render.
  • On those launches, Expo Router's NavigationContainer set state from its initial-URL promise before it had mounted, and React warned "Can't perform a React state update on a component that hasn't mounted yet".

The declaration is unchanged on main.

Change: initialize the field to ReactEventPriority::Default, which is also the value dispatchEvent restores after each event.

Changelog:

[GENERAL] [FIXED] - Initialize UIManagerBinding's current event priority, so an app's first render no longer takes an arbitrary priority (sometimes IdleLane)

Test Plan:

  • Read the field's uses: it is written only in UIManagerBinding::dispatchEvent (set to the event's priority, then reset to Default) and read only by unstable_getCurrentEventPriority. With the initializer, the read before any event returns Default, matching what it returns between events.
  • Observed the bug in a debug build of RN 0.86.3 on an Android emulator, with logs in ReactFabric-dev.js's updateContainer:
    updateContainer lane=32 … fabricPriority=1702129263      (most launches: Default, by fallback)
    updateContainer lane=32 … fabricPriority=0
    prepareFreshStack lanes=268435456                         (another launch: the root's first render on IdleLane)
    
    The IdleLane launch came before we logged the priority value itself; with no transition or JS-side update priority set, only a Fabric priority of 3 (Idle) gives that lane.
  • Not rebuilt from source with this change. It is a one-line default member initializer in a header, with no behaviour change after the first event.

🤖 Generated with Claude Code

The field had no initializer and the constructor does not set it, so
unstable_getCurrentEventPriority returned uninitialized memory until the
first event was dispatched. React reads it when the app first calls
updateContainer, so the first render could get an arbitrary lane,
sometimes IdleLane.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@meta-cla

meta-cla Bot commented Nov 20, 2026

Copy link
Copy Markdown

Hi @biitran0204-spec!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@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 Nov 20, 2026
@meta-cla

meta-cla Bot commented Nov 20, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@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 Nov 20, 2026
@meta-codesync

meta-codesync Bot commented Nov 20, 2026

Copy link
Copy Markdown

@javache has imported this pull request. If you are a Meta employee, you can view this in D133523400.

@christophpurrer christophpurrer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

This branch has not been deployed

No deployments
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.

3 participants