-
Notifications
You must be signed in to change notification settings - Fork 79
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
Support react-router 6 #275
Support react-router 6 #275
Conversation
src/Security.tsx
Outdated
@@ -60,6 +61,10 @@ const Security: React.FC<{ | |||
restoreOriginalUri(oktaAuth as OktaAuth, originalUri); | |||
}) as ((oktaAuth: OktaAuth, originalUri?: string) => Promise<void>); | |||
|
|||
return () => { | |||
// Restore original 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.
Fixes #227 for React 18 StrictMode
src/Security.tsx
Outdated
@@ -60,6 +61,10 @@ const Security: React.FC<{ | |||
restoreOriginalUri(oktaAuth as OktaAuth, originalUri); | |||
}) as ((oktaAuth: OktaAuth, originalUri?: string) => Promise<void>); | |||
|
|||
return () => { | |||
// Restore original callback | |||
oktaAuth.options.restoreOriginalUri = originalCallback; |
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.
I don't think this is necessary, the Security
component should never unmount
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 cleanup function fixes the issue with React 18 StrictMode.
If you run test/apps/v6-app
sample app without it, you can notice the warning Two custom restoreOriginalUri callbacks are detected. The one from the OktaAuth configuration will be overridden by the provided restoreOriginalUri prop from the Security component.
It happens because effects run twice
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.
Oh interesting, that's probably because StrictMode was changed in React18 to do a double mount
I wonder if we should use this approach instead: https://react.dev/learn/you-might-not-need-an-effect#initializing-the-application
Trevor used it as well for something similar: #266
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.
Changed to global var approach.
This required a workaround for tests: 0132a0e
this is really useful, even the updates to the docs are super convenient and helped me a lot. |
Hi everyone We are upgrading an old application to the latest version okta-react and are encountering the same issue of SecureRoute no longer working after going to version Version 6. Will this update be released soon? |
We don't have an official timeline, this is a major version release, so we are proceeding carefully |
Ok, thank you for the clarification! |
OKTA-676780 Support react-router 6
OKTA-676780 Support react-router 6
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: OKTA-676780
Resolves #178
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Reviewers