Skip to content

PiT 23.2: spring-boot based project fails to start in dev-mode when using Vite and @PWA #14146

Closed

Description

@taefi

Description of the bug

If the @PWA is used on the AppShell class, the project fails to start when using Vite with the following error (in dev mode):

java.lang.NullPointerException: Cannot invoke "javax.servlet.ServletConfig.getServletContext()" because the return value of "javax.servlet.GenericServlet.getServletConfig()" is null
	javax.servlet.GenericServlet.getServletContext(GenericServlet.java:123)
	java.base/java.util.Optional.map(Optional.java:260)
	com.vaadin.flow.server.VaadinServletService.getPwaRegistry(VaadinServletService.java:232)
	com.vaadin.flow.server.BootstrapHandler.setupPwa(BootstrapHandler.java:1741)
	com.vaadin.flow.server.communication.IndexHtmlRequestHandler.synchronizedHandleRequest(IndexHtmlRequestHandler.java:124)
	com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
	com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1564)
	com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:299)
	com.vaadin.flow.spring.SpringServlet.service(SpringServlet.java:106)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
	org.springframework.web.servlet.mvc.ServletForwardingController.handleRequestInternal(ServletForwardingController.java:141)
	org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:177)
	org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:51)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:655)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
	org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)

When the above error is shown in the browser (and it is also visible in the console), then it will work after the browser is refreshed.

It works fine in Production mode with Vite.
It works fine in dev mode as well as production mode when using webpack.

This problem is not happening in 23.1.0.

Expected behavior

The application should start normally in dev mode the first time it is loaded in the browser, not just after failing once and reloading the browser.

Minimal reproducible example

  1. Download the default base project from start.vaadin.com with 23.2 (Pre) as the platform version
  2. Run the project via the main class or mvn spring-boot:run

Versions

  • Vaadin / Flow version: 23.2.0.alpha1
  • Java version: 17
  • OS version: macOS
  • Browser version (if applicable): N/A
  • Application Server (if applicable): N/A
  • IDE (if applicable): N/A

Activity

  1. changed the title [-]PiT 23.2: spring-boot based project fails to start in dev-mode when @PWA is present [/-] [+]PiT 23.2: spring-boot based project fails to start in dev-mode when using Vite and @PWA[/+] on Jul 6, 2022
  2. simasch commented on Jul 7, 2022

    @simasch

    I have the same issue with 23.1.2

  3. mshabarov commented on Jul 27, 2022

    @mshabarov
    Contributor

    The same issue replicates with V23.2.0.alpha3, but never replicates with V23.2.0.alpha3 + Flow 23.2-SNAPSHOT (which has a bunch of fixes for service worker handling with Vite).

  4. mshabarov commented on Jul 28, 2022

    @mshabarov
    Contributor

    Also replicates with 23.1.3, but doesn't replicate with Flow 23.2-SNAPSHOT patched with #14229.

  5. added a commit that references this issue on Jul 28, 2022
    8a17462
  6. vaadin-bot commented on Aug 9, 2022

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with Vaadin 23.1.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions