Repository navigation
Description
Prerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
Ionic Framework Version
- v6.x
Current Behavior
When navigating, it seems as if ionic router (under react, at least) is using the wrong instance of a re-used view to push on the stack, clobbering the old instance. It’s a little hard to explain in prose.
Let’s say you start at a FormPage at path "/form/0".
You input some data and submit, and it pushes to a LinkPage at "/link".
The stack is now [FormPage (at path "/form/0"), LinkPage].
LinkPage has a link to "/form/1" which uses the same page component (FormPage) using a route param.
The stack should now push a brand new instance of FormPage, but what happens is that the old instance is pushed onto the stack (the form inputs have the values that were submitted at "/form/0", even though the new path is "/form/1").
Let’s say you now navigate back twice (to the first form) using IonBackButtons, you’ll find that the inputs have all been cleared, seemingly resetting that instance of FormPage.
The stack should be [FormPage (at path "/form/0"), LinkPage, new instance of FormPage (at path "/form/1")]
But the stack seems to be [reseted instance of FormPage (at path "/form/0"), LinkPage, first instance of FormPage (at path "/form/1")]
See the repro for more details!
Expected Behavior
I understand from #19531 and all the other linked/related issues that router caching when pushing onto the stack is a "feature", not a bug (sigh). To get around that, I added a route param to the path that should make it unique and thusly get me a new instance when I push onto the stack. I expect each page rendered at a unique path to be its own instance.
Steps to Reproduce
Clone repro repo, install deps, ionic serve
Type something in the input and submit
Click the link
Observe that the input has your value you just typed a minute ago (it should be a brand spanking new instance of the FormPage)
Click back button
Click back button
Observe that your input value is no longer on the page in the history (the page in the stack should have remained intact)
Code Reproduction URL
Ionic Info
Ionic:
Ionic CLI : 6.20.5 (/Users/eric/.npm/_npx/f6fddb685269761d/node_modules/@ionic/cli)
Ionic Framework : @ionic/react 6.4.1
Capacitor:
Capacitor CLI : 4.6.1
@capacitor/android : not installed
@capacitor/core : 4.6.1
@capacitor/ios : not installed
Utility:
cordova-res : not installed globally
native-run : 1.7.1
System:
NodeJS : v19.2.0 (/usr/local/bin/node)
npm : 8.19.3
OS : macOS
Additional Information
I know there’s some other issues relating to caching and navigation (#19531, among others). Those all state that when you use a unique path (like with a route param), it should not use the cached view. That seems to be broken here.
Activity
ionitron-bot commentedon Dec 21, 2022
Thanks for the issue! This issue has been labeled as
holiday triage. With the winter holidays quickly approaching, much of the Ionic Team will soon be taking time off. During this time, issue triaging and PR review will be delayed until the team begins to return. After this period, we will work to ensure that all new issues are properly triaged and that new PRs are reviewed. In the meantime, please read our Winter Holiday Triage Guide for information on how to ensure that your issue is triaged correctly. Thank you!sean-perkins commentedon Dec 21, 2022
@ericbf thank you for the reproduction and the write-up on the issue. I am able to reproduce and you are correct, when pushing a new route with a unique path parameter, it should be constructing a new instance of the view/component.
This problem is also reproducible when going from
/form/0→/form/1.This does not occur if you move from parameterized routes to static routes, e.g.:
This means somewhere in our comparison logic for parameterized routes, is either matching
/form/:indexagainst/form/:index(not taking into account the path value) or a similar comparison is incorrect.I'll categorize this as a bug so that we can digest it into our backlog.
Thanks!
[-]bug: ionic router seemingly re-uses wrong instance of view with parameterized URLs[/-][+]bug: Ionic React Router is not creating new instances of views with parameterized routes[/+]arifeld commentedon Jan 18, 2023
Hi, is there any estimated ETA on when this issue may be fixed? I am currently working on a project in Ionic React and this bug has unfortunately made it impossible to continue working on it.
Apologies for being brash, just trying to determine whether I should bite the bullet and switch to Ionic Angular given the deadline of my project :'(
sean-perkins commentedon Jan 19, 2023
@arifeld we do not communicate ETAs on bugs/features, as to not over promise and under deliver. This bug is not currently in our active sprint.
I did further exploration of this problem and greatly narrowed the scope. If you want to experiment with the current state of my exploration you can use this dev-build:
Note: I have only validated the workflow from the original reproduction (parameterized route, static route, parameterized route). I have not tested any other routing scenario or even ran our e2e tests against my changes.
As I previously speculated, our routing integration is matching the previous route using
matchPathand that is returning the previous parameterized route as the entering view instead of creating a new instance since the url is different.aeharding commentedon Jul 9, 2023
Hi there! I just wanted to toss out a quick comment that this is the #1 issue wefwef has with Ionic today. I would really appreciate if this was fixed!
Just curious, is this planning to be resolved with the routing refactoring?
sean-perkins commentedon Jul 10, 2023
@aeharding have you tested with the dev-build here: #26524 (comment)? If so, does it resolve the challenge you are experiencing? If not, would you be willing to test and let me know your results?
This problematic behavior could be resolved much sooner than the routing refactor. Here is the estimated changed as it stands today: 7f2685c
If I can get additional feedback on if that proposed change works as expected, without any other regressed routing behaviors, I can open it up for review with the larger team.
aeharding commentedon Jul 10, 2023
Hi @sean-perkins!
Thanks so much for the quick reply. I just tried out the build. It seems to be working to an extent! Route with different parameters are not being reused!
However I have observed three problems in my testing, the first being a blocker.
If it would help, I can create minimal code sample reproductions. Just let me know! I apologize if my explanations are unclear.
Assumed app routes
Assume app with two routes in the router:
/foo/:user/bazProblem one
Summary: Navigating through parameterized routes and then navigating back can leave the page blank
Repro:
/foo/alex/baz/foo/sean/baz/foo/alex. Observe blank tab content - ion-page in the DOM is still set to hidden (it's the right page if you remove theion-page-hiddenclass, just not visible)Problem two
Background: This problem is not a blocker like issue 1 is, but would be nice to be fixed (and also potentially related to issue 1?)
Summary: If you navigate to the same parameterized route separated by an unrelated route, the router appears to reuse the first instance. Then when you navigate back, a new instance is shown.
Repro:
/foo/alex. First instance of user page created./baz/foo/alex. Observe the router is reusing the first instance of user page. (This isn’t necessarily a problem, but it would be ideal to be a new instance.)Problem 3(MOVED TO #27900)Background: This problem is also in the latest production Ionic build. But I thought I would mention it in case it is related. Please let me know if you would like a separate issue for this.
Summary: Swipe gestures stop working after navigating through parameterized routes
/foo/alex/baz/foo/seanaeharding commentedon Jul 31, 2023
Adding another test case that I think is related to problem 3 above! Let me know if you'd like this in a separate issue.
Problem 4(MOVED TO #27900)Background: This problem is regarding replacing a parameterized route using
useIonRouter. There's also a related cosmetic issue here: #24260 but the report in the comment I'm writing is a functional issue.Assumed app routes
/:name/:name/detailsRepro
/one/two/two/detailsNote that this bug doesn't happen without parameterized routes (for example, if I explicitly define /one, /two, /one/details and /two/details it works great)
End user reported here: https://lemmy.world/post/2368724
sean-perkins commentedon Jul 31, 2023
@aeharding thank you so much for the additional issue reports! Let's track the swipe to go back behavior separately.
Problem one is definitely a side effect of my dev-build. I'm still discovering why re-creating the entering view would cause the page to not transition in correctly when navigating back.
Problem two sounds related to the primary issue here, so I can track that together until I have more debugging information to say otherwise and then can split the ticket.
aeharding commentedon Jul 31, 2023
@sean-perkins No problem, just created #27900 to track gesture issues!
sean-perkins commentedon Nov 30, 2023
👋 hello everyone! This has been a fun issue to debug and proposed a resolution for!
Can anyone that is effected by this, try out the dev-build and let me know if you run into any regressions or odd behavior?
Here is an example of the behavior I've tested locally:
Kapture.2023-11-30.at.15.05.04.mp4
aeharding commentedon Nov 30, 2023
@sean-perkins Preliminary tests look great!!
The only thing I am seeing, (which is existing behavior in ionic's react router), is that pushing the exact same route a second time, for example
/foo->/bar->/foostill has swipe back broken when you try to swipe back to the initial instance (and doesn't create a new instance of /foo). Is that considered a separate issue?sean-perkins commentedon Nov 30, 2023
@aeharding thanks for the quick testing! I also have an updated dev-build after running through all our test cases for routing:
Yes! I would consider the swipe to go back a separate issue/fix. The target area for that change will be here:
ionic-framework/packages/react-router/src/ReactRouter/StackManager.tsx
Lines 213 to 311 in a3cd204
fix(react): router creates new view instances of parameterized routes (…
ionitron-bot commentedon Dec 31, 2023
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.