vaadin / flow

Vaadin Flow is a Java framework binding Vaadin web components to Java. This is part of Vaadin 10+.
Apache License 2.0
589 stars 164 forks source link

HistoryChangedHandler ignored when exporting Vaadin application as WebComponent #18879

Open contradictioned opened 4 months ago

contradictioned commented 4 months ago

Description of the bug

When I add a WebComponentExporter for a Component and this component sets a historyChange handler, the handler is not invoked when changing the history.

I know that navigation and routing is not available for WebComponents. The HistoryApi however should be, especially since pushing a new state obviously works.

Expected behavior

The historyChange handler should be invoked when the browser history changes.

Minimal reproducible example

See https://github.com/contradictioned/VaadinWebComponentReproduction2, esp. commit https://github.com/contradictioned/VaadinWebComponentReproduction2/commit/7a13760012c76d899ceba6c70c5a9458e0338741 which is a modification of a starter package.

Import into IntelliJ and run the application for the vaadin part, run a local webserver on port 8000 for serving hostPage/index.html, e.g. python3 -m http.server)

Versions

Flow: 24.3.6 Vaadin: 24.3.6 Java: Oracle Corporation 19.0.2 OS: aarch64 Mac OS X 14.2.1 Browser: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:123.0) Gecko/20100101 Firefox/123.0 Browser: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Live reload: Java active (Spring Boot Devtools): Front end active

(reproducible in both, Firefox and Chrome)

contradictioned commented 4 months ago

PS: It should not be a fundamental problem with WebComponents. When I "manually" register a popstate handler in the WebComponent's configureInstance method like this:

UI.getCurrent()
  .getPage()
  .executeJs("window.addEventListener(\"popstate\", (event) => { console.log(\"hellohistory\") });");

and use the back/forward buttons I see "hellohistory" in the browser console.