-
Notifications
You must be signed in to change notification settings - Fork 232
Component unmounts when using SecureRoute #777
Comments
I experienced same issue. This should help you:
|
Internal ref: OKTA-288357 |
i believe this has to do with the fact that SecureRoute now uses the useHistory hook. If you do a history.push in your child component, this may cause issues when your component is a child of SecureRoute |
Any update on the above issue ? |
If I use this solution. this.props.match becomes undefined. Are you able to read 'id' value ? |
@CodeWaala Are you using the most recent version of |
Yes. I upgraded to 3.0.2, this fixed the issue regarding the props missing the 'match' (#724) but this issue still exists. |
We are hitting this issue as well. Any progress on a fix? |
This interesting as it seems to help, but according to react router documentation: Is okta-react doing something different with this? |
For what it's worth, we've worked around this problem by creating a functionally similar component with a fix. This exact problem can be fixed by modifying these lines to the following. const WrappedComponent = useMemo(() => {
const PassedComponent = component || function() { return null; };
return (wrappedProps) => (<RequireAuth><PassedComponent {...wrappedProps}/></RequireAuth>);
}, [component]); What changed here is that There are other issues with |
I experienced the same issue, @AlexeyBarkow's solution fixed it. Note that This won't work ( <SecureRoute
render={({ component }) => component()}
path="/protected/:id"
component={() => (
<Wrapper>
<Protected />
</Wrapper>
)}
/>; But this will: function WrappedProtected() {
return (
<Wrapper>
<Protected />
</Wrapper>
);
}
<SecureRoute
render={({ component }) => component()}
path="/protected/:id"
component={WrappedProtected}
/>; If you're nesting <SecureRoute
render={({ component }) => component()}
path="/"
component={AppWithRoutes}
/>; |
I was digging into this issue, but I've been unable to reproduce it with recent versions of okta-react (and react-router-dom 5.2.0/react-router 16.13.1) Here's what I tried:
Let us know if you're continuing to see the unmounting issue, and if so, with what versions (including react-router). |
@swiftone I am experiencing the problem with react-router-dom 5.2.0. Below is my set up.
|
@chinanderm - interesting, thanks for the case. We are rewriting SecureRoute( see #872 ) as the current version was never written to support all the |
@chinanderm - I've confirmed your case doesn't unmount/remount using the new code. With that cleared, I'll start our internal CI process to get that version (3.0.5) of okta-react published. |
Thank you! Will upgrade as soon as that's out. |
@chinanderm - okta-react 3.0.5 has been released Closing this ticket as this release should close out the last of the ways to trigger this bug. If anyone still has issues with SecureRoute unmounting with okta-react 3.0.5+, please open a new ticket with details and reference this one. |
In my application, I've noticed that state is lost when switching between matching react router routes when using
SecureRoute
.This previously wasn't an issue in
v.1.2.3
, but I've noticed it in bothv.2.0.1
andv.3.0.1
react-router-dom
isv5.1.2
I'm submitting this issue for the package(s):
I'm submitting a:
Current behavior
The mounted component unmounts when React Router params updated
Expected behavior
I would expect the component to stay mounted and not lose state
Minimal reproduction of the problem with instructions
👇 This is the App with its routes. Notice the
Unprotected
view usesRoute
fromreact-router-dom
andProtected
view usesSecureRoute
from@okta/okta-react
.👇 This is the
Unprotected
view. This functions as expected. As a user, I can increment the counter and when I clickNext Page
the state is persisted because the route still matches.👇 This is the
Protected
view. As a user, I can increment the counter BUT when I clickNext Page
the state in the counter is wiped out. I'm guessing this has to do withSecureRoute
causing the view to unmount; i'm not certain though.Extra information about the use case/user story you are trying to implement
This was NOT an issue in
v1.2.3
, but we noticed this issue in bothv.2.0.1
and the latestv.3.0.1
.Environment
3.0.1
node -v
):12.10.0
The text was updated successfully, but these errors were encountered: