Skip to content
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

Merged
merged 1 commit into from
Dec 11, 2024

Conversation

charlesBochet
Copy link
Member

No description provided.

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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

Comment on lines +28 to 30
setIsAppWaitingForFreshObjectMetadata(true);
await verify(loginToken);
}
Copy link
Contributor

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.

Comment on lines +28 to 29
setIsAppWaitingForFreshObjectMetadata(true);
await verify(loginToken);
Copy link
Contributor

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.

Comment on lines +59 to +64
const setIsAppWaitingForFreshObjectMetadataDebounced = useDebouncedCallback(
() => {
setIsAppWaitingForFreshObjectMetadata(false);
},
100,
);
Copy link
Contributor

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.

Comment on lines 67 to 70
if (isDefined(pageChangeEffectNavigateLocation)) {
navigate(pageChangeEffectNavigateLocation);
setIsAppWaitingForFreshObjectMetadataDebounced();
}
Copy link
Contributor

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;
Copy link
Contributor

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

@charlesBochet charlesBochet merged commit 90c2664 into main Dec 11, 2024
19 checks passed
@charlesBochet charlesBochet deleted the fix-load-tokens branch December 11, 2024 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants