hilla icon indicating copy to clipboard operation
hilla copied to clipboard

CCDM: when invalidating session programatically, previous page is reloaded

Open manolo opened this issue 5 years ago • 5 comments

  • 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.

manolo avatar Feb 13 '20 18:02 manolo

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

manolo avatar Feb 27 '20 07:02 manolo

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.

haijian-vaadin avatar Mar 11 '20 08:03 haijian-vaadin

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.

manolo avatar Mar 27 '20 08:03 manolo

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.

haijian-vaadin avatar Aug 21 '20 06:08 haijian-vaadin

RouterSessionExpirationIT is ignored because of this issue: https://github.com/vaadin/flow/pull/10464

denis-anisimov avatar Mar 29 '21 11:03 denis-anisimov