-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix race condition while loading metadata on sign in #9027
Conversation
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.
PR Summary
This PR introduces state management to handle race conditions during metadata loading on sign-in, with key changes focused on synchronizing the authentication and metadata loading processes.
- Added new
ObjectMetadataItemsGater
component that gates content rendering until metadata is loaded, displaying a loader in the interim - Introduced
isAppWaitingForFreshObjectMetadataState
Recoil state to track metadata loading status across components - Modified
VerifyEffect
to set metadata loading state before token verification - Added debounced state setter in
PageChangeEffect
with 100ms delay to prevent rapid state updates during navigation - Changed default auth modal visibility to true and updated modal display logic for consistent behavior across auth routes
9 file(s) reviewed, 5 comment(s)
Edit PR Review Bot Settings | Greptile
setIsAppWaitingForFreshObjectMetadata(true); | ||
await verify(loginToken); | ||
} |
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.
logic: No error handling for verify() call. Could leave app in permanent loading state if verification fails.
setIsAppWaitingForFreshObjectMetadata(true); | ||
await verify(loginToken); |
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.
logic: isAppWaitingForFreshObjectMetadata is never set back to false after verification completes.
const setIsAppWaitingForFreshObjectMetadataDebounced = useDebouncedCallback( | ||
() => { | ||
setIsAppWaitingForFreshObjectMetadata(false); | ||
}, | ||
100, | ||
); |
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.
style: 100ms debounce may be too short for slower connections or heavy metadata loads. Consider increasing to 250-500ms for better reliability.
if (isDefined(pageChangeEffectNavigateLocation)) { | ||
navigate(pageChangeEffectNavigateLocation); | ||
setIsAppWaitingForFreshObjectMetadataDebounced(); | ||
} |
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.
logic: Setting metadata state after navigation could lead to flash of incorrect content. Consider setting state before navigation.
isAppWaitingForFreshObjectMetadataState, | ||
); | ||
|
||
const shouldDisplayChildren = !isAppWaitingForFreshObjectMetadata; |
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.
style: variable name could be more descriptive like isMetadataReady or shouldRenderContent
No description provided.