Bug in Flow when there's no @PWA in the application

Hi,
When there’s no @PWA in the application (in main layout or view) flow doesn’t generate sw.js (it’s no needed), but some part of flow requests it on every route (page) navigation. It generates unnecessary server requests, even generates 2 threads on web server (I’ve checked it) - for each single page request! Because sw.js is not present this second request is rerouted to com.vaadin.flow.router.RouteNotFoundError (you can check it by implementing BeforeEnterListener.beforeEnter).
I’ve found it because this behavior spoils my security mechanism (there’s unplesent effect of browser being refreshed twice).

I found workaround for this- placing empty sw.js in webapp folder.

Checked on:

  • Vaadin Flow 13.0.7
  • JDK 1.8
  • Firefox 67.0

You can test this bug by doing this:

  • get Base Starter for Vaadin Flow (i’ve got with Spring)
  • implement BeforeEnterListener, place syso in beforeEnter to check what navigationTarget and location is requested
  • with @PWA you’ll get one route request on every page request
  • comment @PWA in MainView, rerun the app
  • with no @PWA yul’ll get two route requests (MainView and sw.js → RouteNotFoundError)

I attached my simple app.

If it’s a bug please make a ticket.

Best regards,
17689563.zip (49 KB)

The application does not in any place reference sw.js after you have removed @PWA. What happens instead is that the browser remembers that there has been a service worker for the same URL, and therefore it tries to refresh that one even if the current version of the application doesn’t have any reference to that file.

You can see this for yourself by using the browser’s developer tools to unregister the old service worker. If firefox, you can do that through about:serviceworkers. After unregistering the service worker, the browser will no longer try to load sw.js until you again open an application with @PWA enabled on the same URL.

So this in itself is not a bug, but I think Vaadin could still make it so that sw.js is hardcoded to show the servlet container’s own 404 page instead of creating a new UI navigated to RouteNotFoundError.

Thanks for the clarification! I did not come up with this :slight_smile: You’re right, at first I set my app as PWA, than decided to remove it. Thank’s a lot for help.
Best regards!