-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
Ionic 4 - StackController Page reuse uses old Page data #16516
Comments
Behavior is likewise the same with Beta 17. Ionic Team: I can update the repo for reproducing the issue to Beta 17 if you wish. Please just let me know. 🙂 Thank you! |
If you could update it for ionic beta 17 then that would be very helpful. |
@bryce13950, the repository for reproducing the issue has now been updated to Beta 17. Please let me know if there's anything else that you would like. Thank you! 😃 |
I spent sometime playing around with this, and I think the issue stems from the reuse strategy in the app.module.ts. I simply removed the following...
Then the pages seemed to update properly. Maybe the ionic route strategy will just need to be removed for your project? |
I'm having the same page caching issue for several weeks now, which is starting to affect critical areas of my applictation for different situations. I am refreshing this thread everyday in hope a solution comes soon. I think it's a fine solution that pages pulled from cached if the user is pressing back/going back in history, but I don't think pages should ever be pulled from cache if navigating to a url (going forward) - even if the page has previously been visited. Example 1: User B logs in from the same application and navigates to 'Home' page. Ionic see's that Home was previously visited (by user A) and instead of instantiating 'Home', the view is pulled from cache and displays everything that User A was seing. Example 2) A user clicks a recieved notification about a new post was created. This navigates to the post wall which will load the new post and show it in the wall. But if the user is already on the post wall or the post wall have been visited already, the component/page is pulled from cache and always display the old data without being able to hook into normal Angular behavior for ngOnInit. --
I tried to use navigateRoot() as suggested by @manucorporat without success: |
@Moelgaard85 Very strange. Could you provide a repo for this, so we have a couple of examples to look at? @KevinKelchen Did removing that provider help you at all? |
@bryce13950, thank you for looking into this and for your response! Sorry it's taken several days to respond--I was sick last week and then spent time trying to investigate this issue further. The suggestion to remove Ionic's implementation of @Moelgaard85, I'm glad to see that I'm not alone! I've been wondering if I'm just doing something unconventional in our application because no one else has commented on this issue experiencing the same thing. If anyone else is experiencing these challenges, please chime in! Hopefully we can then work together towards a solution. 😀 A thought: Yesterday I pinged Mike Hartington on Slack asking,
He graciously responded with,
I did not ask for more details. Perhaps the thought was to find a middle-ground between Angular and Ionic 3 where there are still Pages in the DOM (the "stack") but they can eventually still be destroyed? What if it could work such that when you use the Angular router to "forward" navigate to a Page that it will always add a new Page instead of rolling back the Thank you! |
@bryce13950, I've updated the sample project which reproduces the issue as well as the steps to reproduce in the original post. I left the providing of After debugging through Angular and Ionic navigation code I was able to understand the code path differences between the sample project and our actual application. Turns out I needed to add navigating to a different Page before forward navigating to the same Page/URL again (like our actual application). |
This new article on Medium about ionic 4 and the lifecycle hooks might address our some of the issues we are experiencing: article I am unsure if this article helps us, so I would recommend not closing this github issue until we are certain a bug exists or we need to use the extended Ionic router functionality as explained in the article instead. |
Thanks, @Moelgaard85. That’s a good article from Paul on clearing up misconceptions regarding the existence of Ionic lifecycle hooks in v4. Using something like The post also refers to the vanilla Angular router outlet. This router outlet sounds like it would function more like Beta 16 in which there is no stack at all and only one Page exists in the DOM at a time. I imagine you would also lose the routing animations Ionic provides and perhaps other things. Like Beta 16, I’m not sure these characteristics would be the best fit for us as, like others who had issues with Beta 16, we depend on prior Pages still existing in the DOM. Even if Angular’s outlet seemed to otherwise “work” it would probably be an unconventional configuration that may not be well supported or tested. |
So there's a lot here right now, but if you're looking to not create new instances of pages in V4, just disable the ionic route reuse strategy. This was added as a way to maintain the same behavior as V3. |
Hi @mhartington! 👋 My hope kind of is to create new instances of Pages when forward navigating like v3 did--not to use cached Pages like v4 has introduced. Like @bryce13950 also suggested, I did indeed remove For me it's almost like: I want to have a stack of Pages still in the DOM so when I back-navigate the Page instance is still there (at least the prior Page). However, when I forward navigate I want a fresh Page that's not re-using stuff. At the same time, it's probably not great to keep adding Page after Page to the DOM from a resource consumption standpoint like v3 did. Perhaps there's a middle ground where Pages further back in the history can be cleaned up as you use the application, such as when you forward navigate to the same URL it doesn't pop the stack back to, and re-use, the prior instance of the Page, but rather silently deletes the prior instance of the Page from the DOM. Then when you go back in history to that Page it will be re-initialized. Or something like that. Perhaps this new behavior of using a cached Page in the Thank you for all of your time and assistance! 😀 |
The same happens to my project as well. I can't seem to find a single way to make it work properly. I deleted the Ionic reuse strategy to no avail. All my in page links using the routerDirection="root" will navigate and destroy any pages but the new one. But pages navigated using the imperative Router.navigate() or navigateByUrl() will always stay in memory. replaceUrl: true will not fix this. |
My solution to this issue was using a event emitter Obvservable Subjects to notify the cached view to reload the data. In a service:
In the view that has cache problems:
If the view is cached when I call emitDataUpdatedEvent() the data will be reloaded in the view. |
Thinking that this may be fixed at some point in the future I took an approach to re-use the resolvers on existing route configs to load data for the ActivatedRoute: I've attached a basic component to show how I'm using it. This will call your resolver twice when navigating back to a cached page (once for the new activated route that Angular has made that you don't have access to and once for your cached activated route that the component has reference to). This is not a concern for me as we'll caching in the service layer during navigation transitions can be used to avoid calling the server twice. |
@KevinKelchen could you try the latest nightly and see if you're still having issues here? |
Hi @KevinKelchen, I tried out the repository you provided, and it looks like this issue has been resolved by #17888. Would you be able to try it out using the latest Ionic dev build to ensure that everything is working as you would expect? You can install the nightly using Thanks! |
@daem0ndev and @liamdebeasi, I will give it a shot! Thank you! 😀 |
I am experiencing the same behavior as before. Installing the nightly changed my "@ionic/angular": "^4.2.0-dev.201903291804.8ba82fc",
"@ionic/core": "^4.2.0-dev.201903291804.8ba82fc", @liamdebeasi, is running that command to install the nightly and following the steps to reproduce what you did to check if it resolved the issue? Did you make any other changes? Thanks! |
@daem0ndev reached out to me in effort to reproduce the issue. 😀 I'm not sure why it wasn't appearing during my initial attempts, but after blowing away After updating to Angular 7.2.x, it works as expected! 🎉 Thank you, @daem0ndev! |
As I've learned more, I think there are two related "issues" in this single GitHub issue:
I'm going to close this issue since the primary issue is resolved. 🙂 Thank you! |
@KevinKelchen I have tried
and the Angular version is But still I am facing the problem like, when I navigate back to last page of stack, page reuses the old data. Can you please suggest me on this? |
my package.json me too facing the same problem |
Hi @Topiya and @karvannan-thi, 👋 This was fixed in Ionic Angular 4.2.0. @Topiya, |
My package.json me too facing the same problem |
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. |
Bug Report
Ionic Info
Describe the Bug
(There are arguably two interrelated but separate issues here. If I should create separate issues then please let me know! 🙂)
Forward navigation to a
Page
with the same URL (excluding query parameters) will modify the navigation stack history (not the browser history stack but theStackController
stack, which are different). It will then re-use a previousPage
instance that does not contain the latest navigation data from the forward navigation to the same URL.Steps to Reproduce
Steps to reproduce the behavior:
sidemenu
Angular stater template.npm i
.ionic serve
.List
.Item 1
to forward navigate to the detail screen forItem 1
.Page
. It was then retrieved from the targetPage
from the same service. This pattern was outlined by Josh Morony here. The data in the service is keyed in a dictionary using thenavId
UUID URL query parameter.NavParams
which allowed passing complex data like callback functions and objects which cannot be serialized in a lossless way in the URL or@ionic/storage
.Page
in the browser history.List Detail More
.Item 1
to forward navigate to the detail screen forItem 1
. Note that the timestamp is the old value that was displayed when you initially navigated toItem 1
. This is because theStackController
rolled back the stack and re-used the old instance of thePage
forItem 1
. The newnavId
URL query parameter was not used to retrieve the data from the shared service and thus is not using fresh data on this forward navigation.StackController
navigation stack modification, click theion-back-button
and it will take you to the initialList
Page
instead ofList Detail More
which is the screen you were previously on before revisitingItem 1
.Related Code
The steps to reproduce above link to this repository which is set up to reproduce the issue.
Expected Behavior
I expected forward navigation to a
Page
with the same URL to use the latest, current navigation data from the forward navigation to the same URL and not modify theStackController
navigation stack history.Additional Context
Here is some additional context from a message I posted in #16367:
Note: My definition of "reusing" a Page is when "forward" navigating to a URL and instead of pushing a new Page onto the
StackController
's "stack" it re-uses an instance of the Page that is already present in the stack.I've been having issues with
StackController
as well but on Beta 15. I am using the Angular router imperatively in TypeScript but I believe I was experiencing them as well using the newNavController
(which uses the Angular router).Here's a related behavior I've observed:
When you use the router to "forward" navigate to a Page, if the URL (excluding query parameters) is the same as a Page that is already in the "stack," the
StackController
will remove all of the previous Pages in the stack back to the first occurrence of the matching URL/Page. It then re-uses that first occurrence of the Page in the stack. And so then when you useion-back-button
, which seems to ignore browser history and only uses the stack, the Page you go back to is not what you would expect--it's the Page prior to the first occurrence of the Page in the stack.StackController
's "stack," I've tried working around this issue to some success by creating my own custom back button component that just uses Angular'sLocation.back()
when you click it. This tends to result in a lot of destroyed/re-initializing of Pages whose state you can attempt to preserve by storing off data in a shared service that is keyed with a unique ID (such as a UUID) present in the URL.How
StackController
re-uses Pages has actually been tripping me up in another way:If I use the Angular router to "forward" navigate to a Page with the same URL as one in the
StackController
's stack and I have navigation parameters that I store in a shared service (as opposed to the URL) and key the parameter storage in the service off of a URL query parameter such as a UUID (a query parameter--not using the matrix URL notation as noted at the end of this section), because the Page is being re-used due to a matching URL instead of being considered as different, the new query parameter value is not being used and the Page pulls the previous parameters out of the shared service due to using the old query parameter value.Perhaps the solve is to work around it by just putting the UUID in as a matrix URL notation parameter and effectively opt-out of any
StackController
reuse of Pages.Thank you for all that you do and for making a great framework! 🙂
The text was updated successfully, but these errors were encountered: