Repository navigation
Keep the restricted action RHP on the stack when opening Subscription #101853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b86ded9
6bfe309
4a6db6c
837219e
f13831b
d4f41e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ import variables from '@styles/variables'; | |
| import CONST from '@src/CONST'; | ||
| import ROUTES from '@src/ROUTES'; | ||
|
|
||
| import React, {useCallback, useMemo} from 'react'; | ||
| import React from 'react'; | ||
| import {View} from 'react-native'; | ||
|
|
||
| function WorkspaceOwnerRestrictedAction() { | ||
|
|
@@ -26,11 +26,18 @@ function WorkspaceOwnerRestrictedAction() { | |
| const styles = useThemeStyles(); | ||
| const expensifyIcons = useMemoizedLazyExpensifyIcons(['Unlock']); | ||
|
|
||
| const activeRoute = useMemo(() => Navigation.getActiveRoute(), []); | ||
| const goToSubscription = useCallback(() => { | ||
| Navigation.closeRHPFlow(); | ||
| Navigation.navigate(ROUTES.SETTINGS_SUBSCRIPTION.getRoute(activeRoute)); | ||
| }, [activeRoute]); | ||
| const goToSubscription = () => { | ||
| // Read the active route at press time rather than snapshotting it at mount. This screen stays | ||
| // mounted underneath the Subscription page, so a mount-time snapshot can be taken while | ||
| // Subscription is the focused route, which would make `backTo` point at Subscription itself. | ||
| // `linkTo` then drops the navigation as a no-op and the button stops working after a swipe back. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ CONSISTENCY-15 (docs)Comments should read as plain, natural sentences without stylistic tics like em dashes. This comment uses an em dash ( Split it into two plain sentences: // ...would make `backTo` point at Subscription itself.
// `linkTo` then drops the navigation as a no-op and the button stops working after a swipe back.Reviewed at: f13831b | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in // Subscription is the focused route, which would make `backTo` point at Subscription itself.
// `linkTo` then drops the navigation as a no-op and the button stops working after a swipe back. |
||
| // A press can only happen while this screen is on top, so reading it here always resolves to | ||
| // the restricted-action route. | ||
| // | ||
| // Don't close the RHP here either. Doing so pops this screen off the root stack, so the native | ||
| // swipe-back gesture lands on whatever was underneath instead of returning here. | ||
| Navigation.navigate(ROUTES.SETTINGS_SUBSCRIPTION.getRoute(Navigation.getActiveRoute())); | ||
| }; | ||
|
|
||
| return ( | ||
| <ScreenWrapper | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ CLEAN-REACT-PATTERNS-0 (docs)
React Compiler is enabled in this codebase and automatically memoizes closures based on their captured variables. The PR's own compliance table reports this component passes the React Compiler check, so the manual
useCallbackwrapper here is redundant. Now that the dependency array is[]and the active route is read at press time, the closure captures nothing, making the wrapper pure overhead.Remove the
useCallbackand use a plain function so the compiler can handle memoization:You can then drop the
useCallbackimport from thereactimport statement.Reviewed at: f13831b | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, fixed in
d4f41e4.goToSubscriptionis a plain function now and theuseCallbackimport is gone from thereactimport.The suggestion is right about why: once the active route moved to press time, the closure captures nothing and the dependency array is empty, so the wrapper was doing nothing the compiler doesn't already do.
Verified per the rule's prerequisite before applying —
react-compiler-compliance-check checkon this file reports no failures, so the file does compile and the rule applies.