Skip to content

bug: useLocation may break your app because of mounted pages #27139

Closed
@FernetB

Description

@FernetB

Prerequisites

Ionic Framework Version

v5.x

Current Behavior

If you have 3 pages A, B and C

You go from A -> B with a stateB and then B -> C with stateC the app may crash because when you are on page C, B is mounted and the stateB that returns the useLocation hook, will have the stateC value because you are no longer on B

This is a silly example of an app crashing with this:

https://codesandbox.io/s/holy-waterfall-t9ofg1?file=/src/pages/UserDetailPage/UserDetailPage.tsx

Expected Behavior

Each page should have their useLocation not muting with the new state.

I know that this is not a bug per se, but a bad interaction between useLocation and Ionic with mounted pages.

But is something that needs to be cared about and or offer a solution, or clariy in the documentation

Steps to Reproduce

Easy example:
1 -Click in any User
2 - Then click on More details button
3 - app break
https://codesandbox.io/s/holy-waterfall-t9ofg1?file=/src/pages/UserDetailPage/UserDetailPage.tsx

Code Reproduction URL

https://codesandbox.io/s/holy-waterfall-t9ofg1?file=/src/pages/UserDetailPage/UserDetailPage.tsx

Ionic Info

Ionic:

Ionic CLI
Ionic Framework : @ionic/react 5.9.1

Capacitor:

Capacitor CLI : 4.1.0
@capacitor/android : 4.1.0
@capacitor/core : 4.1.0
@capacitor/ios : 4.1.0

Utility:

cordova-res : 0.15.1
native-run : 1.7.0

System:

NodeJS : v14.17.0
npm : 6.14.13
OS : Windows 10

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions