Skip to content
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

Reload/refresh router content without reloading the full page #19244

Closed
chvndb opened this issue Apr 24, 2024 · 4 comments · Fixed by #19331
Closed

Reload/refresh router content without reloading the full page #19244

chvndb opened this issue Apr 24, 2024 · 4 comments · Fixed by #19331

Comments

@chvndb
Copy link

chvndb commented Apr 24, 2024

I am using Vaadin 24 with a RouterLayout and trying to refresh the router content without refreshing all the other components of the RouterLayout.

Using UI.getCurrent().getPage().reload(); does a full page refresh which is not the UX I want. If I use UI.getCurrent().navigate(...), then it simply reuses the previous router component. This means I need to implement logic that checks if it is a refresh or not and update accordingly.

I want to avoid this overhead and simply have a new instance of the router component so that the content is recreated and acts as a refresh. I tried manipulating the router through UI.getCurrent().getInternals().getRouter(), but could not find a solution.

Is this in any way possible? I can only find issues talking about preserve on refresh.

In the end, I would like something like UI.getCurrent().getPage().refreshRoute(); or UI.getCurrent().getRoute().refresh(); that would make sure a new instance of the route component is created and RouterLayout.showRouterLayoutContent(HasElement content) is called again.

There should also not be any new entry in the browser session history (History). So that navigating back goes to a previous page and not again to the same page.

@chvndb
Copy link
Author

chvndb commented Apr 24, 2024

I found a workaround. It is a hack as I have to use the getInternals() method which is not a stable API and should not really be used as I understood.

I basically clear the routerTargetChain in UIInternals using a fake location. Then I do the actual navigation using the NavigationTrigger.PROGRAMMATIC trigger to avoid a browser history entry.

Location location = ...;  // the location corresponding to the route I want to refresh
UI.getCurrent().getInternals().showRouteTarget(new Location("random"), new Div(), null);
UI.getCurrent().getInternals().getRouter().navigate(UI.getCurrent(), location, NavigationTrigger.PROGRAMMATIC);

This results in the behaviour that I need. Did I miss something that can do the same, but in a clean way? Or is this a feature that could be added?

@mshabarov
Copy link
Contributor

Or is this a feature that could be added?

Yes, Vaadin Flow team is going to implement this feature soon and hopefully this will target Vaadin 24.5 (or maybe even 24.4) release.

@tepi tepi self-assigned this May 6, 2024
@tepi tepi moved this from Next for Dev. Team to Work In Progress in Vaadin Flow enhancements backlog (Vaadin 10+) May 6, 2024
@knoobie
Copy link
Contributor

knoobie commented May 13, 2024

@mshabarov I just came across a use case for this as well. I know it's pretty late for 24.4.. but this looks like a neat and easy addition; some Users and even your Copilot would love to have 😉

@mshabarov
Copy link
Contributor

@knoobie good point, let's see how development goes, I'm okay to include it into 24.4 even though it's in beta already. Copilot experience was the main point, indeed.

Vaadin Flow enhancements backlog (Vaadin 10+) automation moved this from Work In Progress to Done / Pending Release May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Vaadin Flow enhancements backlog (Vaa...
  
Done / Pending Release
Development

Successfully merging a pull request may close this issue.

4 participants