Repository navigation
feat: deliver batched CSS events to JS - #10107
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe PR adds typed CSS animation and transition events, a per-view callback registry, and ChangesCSS native event handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
75e2154 to
e62aee0
Compare
e62aee0 to
3c2af90
Compare
3c2af90 to
97019f6
Compare
97019f6 to
f5db016
Compare
f5db016 to
14928e0
Compare
14928e0 to
7c24779
Compare
7c24779 to
6168b15
Compare
6168b15 to
1e77a4b
Compare
1e77a4b to
e0a45db
Compare
017938d to
c3f7688
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@packages/react-native-reanimated/src/css/native/events/CSSCallbacksRegistry.ts`:
- Around line 46-48: The subscriber callback delivery in the nested event and
subscriber loops exits prematurely when handleCSSEvent throws, preventing later
subscribers and later events from receiving delivery. Wrap the
subscriber.handleCSSEvent(event) call in a try-catch block to capture errors
without exiting the loops. Store only the first caught error in a variable and
continue iterating through all subscribers and events. After both loops
complete, rethrow the captured error if one was encountered. Update the error
test to verify that a later subscriber in the same batch still receives its
event even when an earlier subscriber's handleCSSEvent throws.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 8faeb439-6ff8-4591-b3cd-940826c58af9
📒 Files selected for processing (10)
packages/react-native-reanimated/src/ReanimatedModule/NativeReanimated.tspackages/react-native-reanimated/src/ReanimatedModule/js-reanimated/JSReanimated.tspackages/react-native-reanimated/src/ReanimatedModule/reanimatedModuleProxy.tspackages/react-native-reanimated/src/css/native/events/CSSCallbacksRegistry.tspackages/react-native-reanimated/src/css/native/events/__tests__/CSSCallbacksRegistry.test.tspackages/react-native-reanimated/src/css/native/events/index.tspackages/react-native-reanimated/src/css/native/events/types.tspackages/react-native-reanimated/src/css/native/index.tspackages/react-native-reanimated/src/css/native/proxy.tspackages/react-native-reanimated/src/initializers.native.ts
355eb14 to
df29ca7
Compare
df29ca7 to
d2cc7dd
Compare
d2cc7dd to
b573300
Compare
b573300 to
acf660b
Compare
acf660b to
b39d059
Compare
b39d059 to
38ec587
Compare
91605c5 to
16c9e24
Compare
2a4478a to
ef6b353
Compare
ef6b353 to
a90b33b
Compare
## Description Since Reanimated 4.6.0 (software-mansion/react-native-reanimated#10107), importing `react-native-reanimated` under Jest throws during module evaluation: ``` [Reanimated] `setCSSEventHandler` is not available in JSReanimated. at initializeReanimatedModule (src/initializers.native.ts:22) at Object.<anonymous> (src/index.ts:11) ``` Under `Jest`, `Reanimated` selects its `JSReanimated` module (`IS_JEST` check in `reanimatedModuleInstance.native.ts`), whose `setCSSEventHandler` stub throws, and `initializers.native.ts` calls it unconditionally as an import side effect. Our `reanimatedWrapper` catches the error and silently falls back to `Reanimated = undefined`. This PR mocks `reanimatedWrapper` in `Errors.test.tsx` (same pattern as `runOnJSReanimatedHandlers.test.tsx`), which makes the suite independent of whether the real Reanimated can be imported under Jest. The mock additionally provides `useComposedEventHandler`, which `InterceptingGestureDetector` calls. ## Test plan - yarn test — 19/19 suites, 159/159 tests pass (Errors.test.tsx was failing on main before this change)
The JS half of the CSS events channel: a registry that receives batched events from native and hands each one to the subscribers listening for that view tag, plus the module plumbing that installs the handler.
Subscription is keyed by view tag rather than by object identity, since nested animated components can share a tag. An event can outlive the view it was emitted for, so an event for a tag nobody listens to is dropped.
A batch carries events for unrelated views, so a throwing subscriber is reported through
ErrorUtils.reportFatalErrorrather than left to unwind. The error stays fatal, as an uncaught one would be, without starving the views queued behind it in the same batch.