fix: prevent infinite timezone update loop for delegate sessions#84232
fix: prevent infinite timezone update loop for delegate sessions#84232mayuegood wants to merge 2 commits intoExpensify:mainfrom
Conversation
|
I have read the CLA Document and I hereby sign the CLA 马子夜 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. |
| let lastUpdateTimestamp = 0; | ||
|
|
||
| const useAutoUpdateTimezone = () => { | ||
| const currentUserPersonalDetails = useCurrentUserPersonalDetails(); |
There was a problem hiding this comment.
❌ CLEAN-REACT-PATTERNS-2 (docs)
currentUserPersonalDetails?.account accesses a property that does not exist on the PersonalDetails type (nor on CurrentUserPersonalDetails). This will always be undefined, so isActingAsDelegateSelector(account) will always return false, making the delegate check completely non-functional.
The isActingAsDelegateSelector expects OnyxEntry<Account> from the ONYXKEYS.ACCOUNT Onyx key, not a field from personal details. The established pattern used elsewhere in the codebase (e.g., ProductTrainingContext/index.tsx:62, AddNewCardPage.tsx:50) is:
import useOnyx from '@hooks/useOnyx';
import ONYXKEYS from '@src/ONYXKEYS';
const [isActingAsDelegate] = useOnyx(ONYXKEYS.ACCOUNT, {selector: isActingAsDelegateSelector});Replace lines 12-13 with:
const [isActingAsDelegate] = useOnyx(ONYXKEYS.ACCOUNT, {selector: isActingAsDelegateSelector});And update the references from isDelegate to isActingAsDelegate (or rename as preferred).
Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3eb6e3abd9
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
src/hooks/useAutoUpdateTimezone.ts
Outdated
| const account = currentUserPersonalDetails?.account; | ||
| const isDelegate = isActingAsDelegateSelector(account); |
There was a problem hiding this comment.
Read delegate state from account Onyx key
In useAutoUpdateTimezone, isActingAsDelegateSelector is called with currentUserPersonalDetails?.account, but useCurrentUserPersonalDetails() provides personal-details data (timezone/accountID/etc.), not the ACCOUNT Onyx object that contains delegatedAccess. As a result account is undefined and isDelegate stays false, so delegate sessions still run updateAutomaticTimezone, leaving the delegate loop this change intended to stop effectively unfixed.
Useful? React with 👍 / 👎.
src/hooks/useAutoUpdateTimezone.ts
Outdated
|
|
||
| const THROTTLE_INTERVAL_MS = 60 * 60 * 1000; // 1 hour | ||
|
|
||
| let lastUpdateTimestamp = 0; |
There was a problem hiding this comment.
Scope timezone throttle per active account
The throttle state is stored in a module-level lastUpdateTimestamp, so a timezone update for one signed-in context suppresses updates for every later context in the same app process for an hour. If a user switches accounts/delegators without a full reload, the next active account can keep a stale automatic timezone despite a mismatch, because this shared timestamp blocks its first sync.
Useful? React with 👍 / 👎.
- Use useOnyx to get Account data from ONYXKEYS.ACCOUNT (contains delegatedAccess) - Use useRef to store per-account timestamps instead of global variable - Each account now has its own throttle timer
Updated FixI've updated the PR with corrections for the two issues identified: Fix 1: Correct Account data location
Fix 2: Per-account throttle timer
The fix has been pushed to the PR. |
|
@mayuegood This PR is against the rules of our contributor program. You're required to submit a proposal in the parent issue first and submit a PR only when your proposal is accepted. |
Context
Fixes issue #83765 - Infinite timezone update loop on multi-device setups with different timezones.
Changes
Related Issues
$ #83765