[v2] Refactor ReanimatedModal/index.tsx to follow Rules of React and compile with React Compiler#90555
Draft
roryabraham wants to merge 18 commits into
Draft
[v2] Refactor ReanimatedModal/index.tsx to follow Rules of React and compile with React Compiler#90555roryabraham wants to merge 18 commits into
roryabraham wants to merge 18 commits into
Conversation
…Compiler - Group useEffects by responsibility; co-locate cleanup with creation - Extract transition callbacks with useEffectEvent to fix stale closure - Derive isTransitioning and eliminate redundant isVisibleState state - Remove manual memoization (useCallback/useMemo) superseded by React Compiler - DRY up clearTransitionHandles helper - Sort component internals: hooks, refs, derived, callbacks, effects Co-authored-by: Cursor <cursoragent@cursor.com>
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
Covers four staging regressions from the React Compiler refactor: - #90438 RHP no animation (derived isTransitioning loses "in-progress" semantics on oscillation) - #90442 Android can't confirm deletion (interaction handle cleared prematurely) - #90463 Android modal not displayed (interaction handle cleared prematurely) - #90510 Web flickering on close (Container unmounted before exit animation plays) Tests are intentionally red until the fixes are applied. Co-authored-by: Cursor <cursoragent@cursor.com>
Wraps onBackButtonPressHandler and handleEscape in useEffectEvent so they hold a stable reference across renders without needing deps. The back handler effect can now use [] as its dep array, eliminating re-registration on every render cycle. Fixes #90442 and #90463. Co-authored-by: Cursor <cursoragent@cursor.com>
Replaces two booleans (isContainerOpen + derived isTransitioning) with a single explicit ModalState enum: 'closed' | 'opening' | 'open' | 'closing'. The enum makes impossible states impossible and fixes oscillation bugs: - modalState only advances via animation callbacks (onOpenCallBack / onCloseCallBack), so it can never flip back due to isVisible oscillating. - The isVisible → state transition uses the render-time state adjustment pattern instead of a useEffect, eliminating extra renders. - Container visibility uses (modalState === 'opening' || modalState === 'open') so the Container unmounts when closing begins, triggering Reanimated's ghost- node exit animation, and does not re-mount during isVisible oscillation. Updates regression tests to use reliable spy-count assertions; removes dependency on InteractionManager.runAfterInteractions which is mocked to fire immediately in the test environment. Fixes #90438, #90510. Co-authored-by: Cursor <cursoragent@cursor.com>
Extract TransitionTracker and InteractionManager handle management out of React state and into a new useAnimationTransition hook. Handles now start on component mount/unmount (via useLayoutEffect) and end when the animation callback fires (onAnimationComplete), bypassing React state as an intermediary. This fixes a class of bugs where React's re-render cycle could clear or create handles at the wrong time, and removes the useEffect that was responsible for the premature cleanup regressions. Update the Container mock in tests to use the real useAnimationTransition hook so spy assertions on TransitionTracker and InteractionManager remain meaningful. Remove the useEffect safety net from useAnimationTransition as it ran synchronously on unmount, immediately ending the exit-animation handle before Reanimated's ghost-node could complete its animation. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Add useOnValueChange<T>(value, onChange) — a thin wrapper around React's render-time state adjustment pattern. Runs onChange synchronously during render (no intermediate DOM commit), unlike useEffect which fires after paint. Uses Object.is for comparison to match React's own semantics. Use it in ReanimatedModal to replace the manual prevIsVisible state variable. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
GestureHandler and Container already default swipeThreshold to 100, so the required constraint on the prop type was unnecessarily strict. Co-authored-by: Cursor <cursoragent@cursor.com>
Modals don't require content to render — the prop should be optional to allow unit tests and other callers to omit it. Co-authored-by: Cursor <cursoragent@cursor.com>
When a modal is mounted with isVisible=true (e.g. ConfirmModalWrapper), useOnValueChange only triggers on changes, so the initial 'closed' state was never advanced, preventing the modal content from ever rendering. Co-authored-by: Cursor <cursoragent@cursor.com>
16a034d to
d62eb4d
Compare
Contributor
|
🚧 @roryabraham has triggered a test Expensify/App build. You can view the workflow run here. |
This comment was marked as outdated.
This comment was marked as outdated.
…er with React Compiler - Backdrop/index.tsx: inline BackdropOverlay JSX variable (partial render anti-pattern) - Container/index.tsx: remove manual useMemo for Entering/Exiting; replace Partial<ReanimatedModalProps> with self-contained ContainerProps - Container/index.web.tsx: remove manual useMemo for Exiting; add animationIn to useAnimatedStyle deps - GestureHandler.tsx: remove manual useMemo for panGesture - types.ts: expand ContainerProps with native-only fields; remove animationInDelay from BackdropProps (never consumed) - index.tsx: remove animationInDelay pass-through to Container and Backdrop Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
|
🚧 @roryabraham has triggered a test Expensify/App build. You can view the workflow run here. |
Contributor
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
Author
|
requested AdHoc testing: https://expensify.slack.com/archives/C09V78U42D8/p1778795508021849 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation of Change
This is v2 of #90358, which was reverted due to staging regressions. This version contains the original refactoring changes plus fixes for all four reported regressions.
Regressions fixed:
Root cause: The original refactor derived
isTransitioningfromisVisible !== isContainerOpen. WhenisVisibleoscillated back to matchisContainerOpenmid-animation (e.g. rapid RHP navigation),isTransitioningincorrectly becamefalse, prematurely ending transition handles and allowing the Container to re-mount mid-animation.Fix: Replace the two booleans with a four-state enum (
closed | opening | open | closing). State advances only from stable states (closed → opening,open → closing) and is latched through animations, so mid-animation oscillations are ignored. MoveTransitionTracker/InteractionManagerhandle management out of React state and into a newuseAnimationTransitionhook that ties directly to component mount/unmount and animation callbacks, bypassing React's render cycle.Fixed Issues
$
PROPOSAL:
Tests
Regression #90510 — web flash on RHP close:
5. On web, open the Search RHP (tap the search icon in the Inbox header).
6. Close it by clicking outside or pressing Escape.
7. Verify the chat list does not briefly reappear over the area where the RHP was.
Regression #90438 — RHP animation missing after navigation:
8. On web, go to Workspace Settings → Distance rates → Settings → Unit.
9. Select a different unit and navigate back.
10. Verify the RHP animates on every open/close without getting stuck unanimated.
Regression #90463 — modal not displayed on Android:
11. On Android: Workspace → Tags → More → Import spreadsheet → Multi-level tags → Upgrade → Got it, thanks → Switch Tag Levels.
12. Verify the Import spreadsheet modal appears with a "Choose file" button.
Regression #90442 — confirmation modal missing on Android:
13. On Android: create an expense → open the expense report → More → Delete → Delete.
14. Verify the expense is successfully deleted. Also verify delete/remove actions work for: saved searches, workspace members, categories, tags, distance rates, taxes, per diem rates.
Offline tests
N/A — no offline-specific behavior changed.
QA Steps
Regression #90510 — web flash on RHP close (web):
4. Navigate to Inbox → click the search icon → close the Search RHP by clicking outside or pressing Escape.
5. Verify chats do not briefly reappear on screen where the RHP was displayed.
Regression #90438 — RHP animation stops (web):
6. Go to Workspace Settings → Distance rates → Settings → Unit → select another unit.
7. Verify the RHP animates on every subsequent open/close.
Regression #90463 — modal not displayed on Android:
8. On Android: Workspace → Tags → More → Import spreadsheet → Multi-level tags → Upgrade → Got it, thanks → Switch Tag Levels.
9. Verify the Import spreadsheet modal appears with a "Choose file" button.
Regression #90442 — confirmation modal missing on Android:
10. On Android: create an expense → open the expense report → More → Delete → Delete.
11. Verify the expense is successfully deleted. Also verify delete/remove actions work for: saved searches, workspace members, categories, tags, distance rates, taxes, per diem rates.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
Made with Cursor
/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)Screenshots/Videos