flow icon indicating copy to clipboard operation
flow copied to clipboard

Embedded vaadin flow component disappears after session timeout and also loads styles from wrong location.

Open ggecy opened this issue 1 year ago • 6 comments

Description of the bug

I have a vaadin flow component exported through WebComponentExporter and embedded in another page. When I e.g. let the laptop sleep for longer than session timeout duration or just put the browser to offline in Network tab in Developer tools, the server session expires in meantime and the embedded component disappears from page - it's still there in html source, but with nothing inside its shadow-root except one style element. I managed to replicate it also with latest skeleton starter application downloaded from vaadin.com where I just added the WebComponentExporter for the sample view, added cors filter bean registration and set the servlet session timeout to 60 seconds. After waiting for over 60 seconds in offline mode and then disabling offline mode the embedded component tries to resynchronize on next heartbeat or any other request to server and then disappears.

Also the embedded component tries to incorretly download styles from wrong host - my vaadin flow app is running on port 8080 and the embedded components tries to load styles from the page where it is embedded instead.

Browser console log: localhost-1718905756488.log

Screenshot 2024-06-20 at 19 50 37

Expected behavior

Embedded flow component should not dissapear after server session expires. Styles should be loaded from correct url.

Minimal reproducible example

See https://github.com/ggecy/embedded-component-issues

  1. Clone the repo, build and start the vaadin application. I changed the session timeout to 60 seconds and heartbeat to 15 seconds. There is also cors filter registration bean to add cors headers. I also added WebComponentExporter for sample view.
  2. In react-app subfolder, I created a blank react app where in public/index.html I added the embedded webcomponent. Go to this subfolder and run npm install and then npm run start to start the app on port 3000.
  3. Open the http://localhost:3000 in chrome, the page should open with embedded component displayed. Open developer tools and in Network tab at the top choose Offline from throttling menu.
  4. Wait for longer than 60 seconds until session expires on backend.
  5. Change offline mode back to no thottling.
  6. The embedded component should try to resynchronize with server on next heartbeat or when you try to submit a value from textfield.
  7. Embedded component disappears.

Versions

  • Vaadin / Flow version: 24.4.3
  • Java version: 17
  • OS version: MacOS 14.5
  • Browser version (if applicable): Arc 1.47.1 (latest)
  • IDE (if applicable): Intellij Idea Ultimate

ggecy avatar Jun 20 '24 18:06 ggecy

It seems that during resynchronize, some code tries to set the exported web component $server.disconnected function while $server is undefined, it seems to be this place: https://github.com/vaadin/flow/blob/e4c75ce01c985722dc4550b697fd48ea8e6e7baf/flow-client/src/main/java/com/vaadin/client/SystemErrorHandler.java#L193

ggecy avatar Jun 22 '24 12:06 ggecy

See also: https://vaadin.com/forum/t/embedded-vaadin-flow-component-disappears-after-session-timeout/166573

TatuLund avatar Jul 22 '24 08:07 TatuLund

Any updates? This has been under investigation for over a month now...

ggecy avatar Jul 25 '24 10:07 ggecy

No updates unfortunately, we have no solution at the moment, but will be keeping an eye on it and continue as soon as we can.

mshabarov avatar Aug 28 '24 07:08 mshabarov

I'm struggling with the same issue.

Is there any possiblity to remove or shutdown a web component completely, without reloading the page?

Thanks

pmneo avatar Oct 09 '24 07:10 pmneo

What I found is that there is something happening when Push is in use. So if I do not have Push enabled the resync works, but with push enabled there are 2 webcomponent-resync calls which breaks the webcomponent.

So as a workaround one can use polling from the webcomponent instead of push while we try to get a fix for the problem with push.

caalador avatar Oct 23 '24 11:10 caalador

This ticket/PR has been released with Vaadin 24.6.0.alpha3 and is also targeting the upcoming stable 24.6.0 version.

vaadin-bot avatar Nov 13 '24 10:11 vaadin-bot

This ticket/PR has been released with Vaadin 24.4.17.

vaadin-bot avatar Nov 18 '24 14:11 vaadin-bot

This ticket/PR has been released with Vaadin 24.5.5.

vaadin-bot avatar Nov 19 '24 07:11 vaadin-bot

Theme css is still loaded from wrong path even with vaadin version 24.6.0. React app is running at http://localhost:3000, vaadin is running on http://localhost:8080, the web component is loaded from http://localhost:8080/web-component/commons-template-main-view.js but it adds <link rel="stylesheet" type="text/css" href="VAADIN/themes/my-theme/document.css"> to header (without correct host and port) and this file is obviously not accessible at http://localhost:3000/VAADIN/themes/my-theme/document.css

ggecy avatar Mar 13 '25 23:03 ggecy

Re-opened for further investigation.

mshabarov avatar Mar 14 '25 06:03 mshabarov

This ticket/PR has been released with Vaadin 24.8.0.alpha2 and is also targeting the upcoming stable 24.8.0 version.

vaadin-bot avatar Mar 17 '25 13:03 vaadin-bot

This ticket/PR has been released with Vaadin 24.5.14.

vaadin-bot avatar Mar 18 '25 06:03 vaadin-bot

This ticket/PR has been released with Vaadin 24.6.7.

vaadin-bot avatar Mar 18 '25 11:03 vaadin-bot