bug: Route components not being unmounted correctly
See original GitHub issueBug Report
Ionic version:
[x] 5.x
Current behavior: Route components aren’t unmounted correctly after navigation and preserves the state of components.
Expected behavior: It should be a “clean slate” when re-entering route components similarly to how it works with other react components.
Steps to reproduce:
I have linked a code sand box that shows the issue. Each route has a stateful component (using xstate) and on browsing between the two routes the state is preserved between the routes. Note this doesn’t happen with react’s setState
but does happen in this case due to the use of useRef
. As noted on the react docs, useRef should only last for the lifetime of the component which suggests that the components aren’t being unmounted.
Related code:
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
react router not unmounting previous content when route is ...
You have a couple options: Move the key to the correct component. It is rather irrelevant on the Route component. Move the key...
Read more >Handling Mounting And Unmounting Of Navigation Routes In ...
Let's look at how to mount and unmount navigation stack based on a met ... Custom components in React Native (how to create...
Read more >Avoid React state update warnings on unmounted components
React raising a warning when you try to perform a state update on an unmounted component. React setState is used to update the...
Read more >Reconciliation - React
Just to be clear, rerender in this context means calling render for all components, it doesn't mean React will unmount and remount them....
Read more >How To Handle Async Data Loading, Lazy Loading, and Code ...
When you do, you'll be able to toggle the details without an error. No warning when toggling, 6. When you unmount, the component...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I tried setting up a fresh sandbox but ionic and code sandbox don’t seem to be playing together for some reason: https://codesandbox.io/s/ionic-smoke-test-62vvv I’ll try again in a day or two.
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.