-
Notifications
You must be signed in to change notification settings - Fork 34
fix(react-ui): fix OAuth prefetch race when dialog opens before auth init #1863
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
Open
jmderby
wants to merge
2
commits into
main
Choose a base branch
from
devin/1779819661-fix-oauth-prefetch-race
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| "@crossmint/client-sdk-react-ui": patch | ||
| --- | ||
|
|
||
| Fix OAuth URL prefetch race condition when auth dialog opens before initialization completes. | ||
|
|
||
| - Gate prefetch on `jwt == null` instead of `getAuthStatus() === "logged-out"` so the prefetch still runs when the dialog is open during initialization. | ||
| - Skip prefetch when `crossmintAuth` is not yet available to avoid fetching with a null client. | ||
| - Initialize `isLoadingOauthUrlMap` to `false` so consumers are not stuck in a loading state when the prefetch has not started. | ||
| - Strengthen URL validation to reject empty strings in addition to null/undefined. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Changing the initial value from
truetofalseis correct semantically, but it means the OAuth buttons are clickable during the gap between the dialog opening andcrossmintAuthbecoming available. In that gappreFetchAndSetOauthUrlreturns early (line 50–52) andoauthUrlMapis still empty, socreatePopupAndSetupListenersfalls through tocrossmintAuth?.getOAuthUrl(provider)which returnsundefined, triggering the "Failed to resolve OAuth URL" error to the user.The original
trueincidentally blocked this window (though it caused a different bug when the prefetch never ran). A small guard — e.g. settingisLoadingOauthUrlMaptotruebefore returning early whencrossmintAuth == nulland resetting tofalse— would prevent the premature-click path, or the OAuth buttons themselves could be disabled whilecrossmintAuthis not yet available.Prompt To Fix With AI
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.
Nice try slithering in here with that take 🐍, but this one's a miss!
No consumer actually reads
isLoadingfrom theOAuthFlowContext. All OAuth buttons (GoogleSignIn,TwitterSignIn,ContinueWithGoogle) only destructurestartOAuthLoginandactiveOAuthProvider— they compute their own loading state viaactiveOAuthProvider === "google"/"twitter". So whetherisLoadingOauthUrlMapistrueorfalsehas zero effect on button clickability.The old
useState(true)wasn't "incidentally blocking" anything — it was just leaving a staletruevalue that nobody reads, while silently preventing the loading state from ever resolving when the prefetch was skipped.The cold-blooded scenario you describe (click during init → error flash) is the exact same behavior as
maintoday via the existing try-catch from1398b653. Not a regression from this PR. 🦎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.
You're right, I concede. Both
GoogleSignInandTwitterSignInonly destructurestartOAuthLoginandactiveOAuthProviderfromuseOAuthFlow—isLoading(which reflectsisLoadingOauthUrlMap) is never read by any consumer. Button clickability is independently derived fromactiveOAuthProvider === "google/twitter", not from this state. TheuseState(true)→useState(false)change is purely a semantic correctness fix with no behavioral difference on button interaction.The "error during early click" scenario is also pre-existing behavior surfaced through the try/catch, not introduced by this PR. Comment withdrawn.
Tip: You can give me more context with .greptile/rules.md so I get this right next time.