hilla
hilla copied to clipboard
CCDM: when invalidating session programatically, previous page is reloaded
- open 'foo' router
- navigate to 'invalidate' by clicking on the link
'invalidate' view should be displayed after the navigation happens, but 'foo' is shown instead.
@Route(value = "foo", layout = Layout.class)
public class MyView extends Div {
public MyView() {
getElement().appendChild(ElementFactory
.createRouterLink("invalidate", "invalidate"));
}
}
@Route(value = "invalidate", layout = Layout.class)
public class MyInvalidateView extends Div implements BeforeEnterObserver {
@Override
public void beforeEnter(BeforeEnterEvent event) {
VaadinSession.getCurrent().getSession().invalidate();
}
}
Probably happening because window.reload
is executed before history.pushState
updating the route.
This fix is needed to enable RouterSessionExpirationIT
but the first failure of the test is because of ending slash is not working as described in vaadin/flow#7583
I made this pr https://github.com/vaadin/flow/pull/7789 to revert the fix since it results in an endless loop. Let's reopen the ticket.
The loop problem that happens when testing the code in the snippets describing this issues is a expected behaviour. It works in this way in v14. Thus, we need to apply the PR again.
Reopen this ticket, as the fix is now reverted at https://github.com/vaadin/flow/pull/8870. Because the fix breaks a more common way of log out, see https://github.com/vaadin/flow/issues/8627.
An easy workaround for this issue could be to redirect user to another view e.g. login view (which is also a more common way of programmatically logging out).
@Route(value = "invalidate", layout = Layout.class)
public class MyInvalidateView extends Div implements BeforeEnterObserver {
@Override
public void beforeEnter(BeforeEnterEvent event) {
VaadinSession.getCurrent().getSession().invalidate();
UI.getCurrent().getPage().setLocation("login");
}
}
The root cause of this is the RouterLink doesn't work exactly the same way with the client-side routing.
As there is an easy workaround, will also deprioritize the ticket.
RouterSessionExpirationIT
is ignored because of this issue: https://github.com/vaadin/flow/pull/10464