Use ref for policyData in WorkspaceUpgradePage to prevent infinite render loop#83880
Use ref for policyData in WorkspaceUpgradePage to prevent infinite render loop#83880MarioExpensify merged 1 commit intomainfrom
Conversation
…nder loop The usePolicyData hook returns an unstable object reference on every render, causing confirmUpgrade to be recreated each cycle. This triggered the useFocusEffect cleanup repeatedly after upgrade (when isUpgraded=true), calling enablePolicyRules in an infinite loop and freezing the app. Using a ref breaks the dependency chain while keeping the latest value accessible in the callback. Co-authored-by: Mario Mazzotti <MarioExpensify@users.noreply.github.com>
|
@MarioExpensify Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
JmillsExpensify
left a comment
There was a problem hiding this comment.
Everything listed in the testing steps conforms with intended product behavior.
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safari83880_web_chrome.mov |
|
🚧 @MarioExpensify has triggered a test Expensify/App build. You can view the workflow run here. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
Use ref for policyData in WorkspaceUpgradePage to prevent infinite render loop (cherry picked from commit 3c51c7f) (cherry-picked to staging by blimpich)
|
🚀 Cherry-picked to staging by https://github.com/blimpich in version: 9.3.30-3 🚀
|
|
🚀 Deployed to production by https://github.com/blimpich in version: 9.3.30-3 🚀
|
|
🚀 Cherry-picked to staging by https://github.com/blimpich in version: 9.3.31-0 🚀
|
|
🚀 Deployed to production by https://github.com/blimpich in version: 9.3.31-12 🚀
|
Explanation of Change
The
usePolicyDatahook returns a new object reference on every render (it lacksuseMemoon its return value). InWorkspaceUpgradePage, this unstable reference was listed as a dependency of theconfirmUpgradecallback, causing it to get a new identity every render cycle. After the optimistic upgrade setisUpgraded=true, theuseFocusEffectcleanup would fire on each render (becauseconfirmUpgradekept changing), callingenablePolicyRulesin an infinite loop that froze the app.This PR stores
policyDatain a ref and accesses it viapolicyDataRef.currentinsideconfirmUpgrade, removingpolicyDatafrom the callback's dependency array. This breaks the infinite dependency chain while still providing the latest data when the callback executes.Fixed Issues
$ #82310
PROPOSAL: #82310 (comment)
Tests
Offline tests
QA Steps
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
N/A - No UI changes
Android: mWeb Chrome
N/A - No UI changes
iOS: Native
N/A - No UI changes
iOS: mWeb Safari
N/A - No UI changes
MacOS: Chrome / Safari
N/A - No UI changes