-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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 useHandleCallback
compatibility with React.StrictMode
#10486
Merged
Conversation
This file contains 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
djhi
requested changes
Jan 31, 2025
Comment on lines
34
to
55
handleCallbackPromise = new Promise(async (resolve, reject) => { | ||
if (authProvider) { | ||
if (typeof authProvider.handleCallback === 'function') { | ||
try { | ||
const result = | ||
await authProvider.handleCallback({ | ||
signal, | ||
}); | ||
return resolve(result ?? null); | ||
} catch (error) { | ||
return reject({ | ||
redirectTo: false, | ||
message: error.message, | ||
}); | ||
} | ||
} | ||
return resolve(); | ||
} | ||
return reject({ | ||
message: 'Failed to handle login callback.', | ||
}); | ||
}); |
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.
This changes the previous behavior. Please revert to the original code. Only keep the handleCallbackPromise
creation as you did
djhi
approved these changes
Jan 31, 2025
djhi
changed the title
Make useHandleCallback compatible with StrictMode
Fix Jan 31, 2025
useHandleCallback
compatibility with React.StrictMode
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Many authentication providers do not accept calling their methods for validating authentication callbacks multiple times. We had the case with
ra-auth-auth0
andra-keycloak
(maybe evenra-supabase
).Our solution until now was to implement the necessary logic in the
authProvider
implementation (storing ongoing promise in theauthProvider
closure). This is fine but it means custom implementations must do it themselves too and this is not trivial for many.Solution
Make the
useHandleCallback
resilient toStrictMode
. Implement the logic that won’t callauthProvider.handleCallback
if another call is already ongoing.How To Test
Revert the fix in useHandleAuthCallback.ts and run the test "should only call handleCallback once when the component is rendered" in
useHandleAuthCallback.spec.tsx
.Additional Checks
master
for a bugfix, ornext
for a feature[ ] The PR includes one or several stories (if not possible, describe why)[ ] The documentation is up to dateScreenshot
Test without the fix: