Skip to content

fix: retry worklet registration when view tag resolves late - #1613

Open
JoaoPauloCMarra wants to merge 1 commit into
kirillzyusko:mainfrom
JoaoPauloCMarra:fix/retry-event-handler-registration
Open

fix: retry worklet registration when view tag resolves late#1613
JoaoPauloCMarra wants to merge 1 commit into
kirillzyusko:mainfrom
JoaoPauloCMarra:fix/retry-event-handler-registration

Conversation

@JoaoPauloCMarra

Copy link
Copy Markdown
Contributor

📜 Description

Retry worklet-handler registration for up to two animation frames when a React ref exists but Fabric has not exposed its native view tag yet. Pending registration is cancelled during cleanup, including registration that was already deferred to a microtask.

💡 Motivation and Context

Fixes #1612.

useEventHandlerRegistration currently checks findNodeHandle only once when viewTagRef.current is populated. During a Fabric mount, the ref can become available before its native tag. If that check returns null, the library logs a warning and leaves the handler detached for the lifetime of the mounted provider.

Runtime reproduction:

  1. Enable Fabric/New Architecture and Hermes.
  2. Wrap the app with KeyboardProvider and mount a consumer such as useKeyboardHandler, KeyboardToolbar, or KeyboardAwareScrollView during the initial provider mount.
  3. Cold-launch or Fast Refresh until the ref is assigned before its native tag.
  4. Observe the view tag can not be resolved warning and missing worklet callbacks for that provider.

The deterministic regression holds findNodeHandle at null for the initial lookup and two animation-frame lookups. Before this change, registerForEvents is never called. With this change, registration succeeds when the tag appears on the second frame.

Platform scope:

📢 Changelog

JS

  • Retry handler registration when a Fabric view tag resolves shortly after its React ref.
  • Cancel pending or deferred registration during cleanup.

🤔 How Has This Been Tested?

  • Added a regression test where the native tag becomes available after two animation frames.
  • Added cleanup tests for a pending animation frame and an already queued microtask.
  • yarn test src --runInBand — 27 suites, 217 tests passed.
  • cd example && yarn test --runInBand — 11 suites, 23 tests passed.
  • cd FabricExample && yarn test --runInBand — 11 suites, 23 tests passed.
  • yarn typescript
  • yarn lint
  • yarn prettier '**/*' --ignore-unknown --check

📸 Screenshots (if appropriate):

Not applicable. The regression is handler registration timing; its stable signals are the warning and missing callbacks.

📝 Checklist

  • CI successfully passed
  • I added new mocks and corresponding unit-tests if library API was changed

@github-actions

Copy link
Copy Markdown
Contributor

📊 Package size report

Current size Target Size Difference
337749 bytes 337064 bytes 685 bytes 📈

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.

Worklet handlers do not register when a Fabric view tag resolves late

1 participant