vite-plugin-pwa icon indicating copy to clipboard operation
vite-plugin-pwa copied to clipboard

Feature Request: Vite PWA Support for React Router 7

Open kazem3d opened this issue 11 months ago • 9 comments

Hi React Router has recently merged with Remix, introducing new features and improvements in version 7. However, it is unclear how to properly configure Vite PWA to work seamlessly with React Router 7. This integration is critical for enabling PWA functionality in applications using the latest React Router version.

kazem3d avatar Dec 27 '24 20:12 kazem3d

Does Remix PWA package work with React Router 7?

Miloshinjo avatar Jan 15 '25 00:01 Miloshinjo

Does Remix PWA package work with React Router 7?

No

kazem3d avatar Jan 15 '25 04:01 kazem3d

The only problem I'm having is about importing virtual modules in the remix pwa components, cannot load virtual modules on SSR (npx create-remix@latest + adding PWA stuff).

image

userquin avatar Jan 15 '25 13:01 userquin

You can copy/paste both components to your app folder, importing them from local works: https://discord.com/channels/770287896669978684/1239208602024280076

userquin avatar Jan 15 '25 14:01 userquin

VitePWA don't work on react router 7? it simply doesn't register/import the service workers, the install button doesn't appear and nothing...

sandercoffee avatar Mar 19 '25 15:03 sandercoffee

You can copy/paste both components to your app folder, importing them from local works: https://discord.com/channels/770287896669978684/1239208602024280076

The page doesn't open, what is the link to enter the server? Or, can you paste the code here? thx

sandercoffee avatar Mar 19 '25 15:03 sandercoffee

Just copy the components here https://github.com/vite-pwa/remix/tree/main/src/components to your src/components folder then use them in your root.tsx (copy only the one you're using, I mean, if not using PWA assets on the fly copy and use PWAManifest, otherwise copy and use the PWAAssets one): https://github.com/vite-pwa/remix/blob/main/examples/pwa-simple-sw/app/root.tsx (just switch this import import { PWAManifest } from '@vite-pwa/remix/components' to use the manifest from your src/components folder

userquin avatar Mar 19 '25 15:03 userquin

If still not working, provide a minimal reproduction :pray:

userquin avatar Mar 19 '25 15:03 userquin

Is there official support for react router 7 (specifically SSR) planned?

genox avatar Mar 26 '25 09:03 genox

Any update?

vimutti77 avatar Aug 27 '25 18:08 vimutti77

@userquin There is a reproduction of vite-pwa's failure to work reliably with React-Router 7 in this repo with more details in this issue that I raised with RR7 that was turfed over here. Basically, there is a very specific issue in the build process that causes several problems:

The issue is that during the build process, vite-plugin-pwa is run after babel is run by RR7 to build the bundled JS code (which is when most of the assets are produced) but before the the SSR code is built -- which is when index.html is produced (e.g. in "SPA mode" with ssr=false in react-router.config.ts, or when pre-rendering index.html with RR7 via the prerender: ["/"] configuration), and so index.html is always excluded from the pre-cache list.

This issue causes these 3 problems:

  1. When using strategies: "generateSW" (the default), the generated service worker includes, this line:
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html")));

which throws the following error because index.html is excluded from the pre-cache list:

Uncaught (in promise) non-precached-url: createHandlerBoundToURL('index.html') was called, but that URL is not precached. Please pass in a URL that is precached instead.
  1. The exclusion of index.html from the cache means the app can never be run offline.
  2. When using additional strategies with generateSW, (i.e. via VitePWA({ workbox: { runtimeCaching: [ ... ] }}) ), the additional workbox strategies are injected into the service worker after the the above line, and so the error shown in (1) also causes any additional workbox caching behaviors to fail silently.

I hope you're able to address this issue. vite-pwa promises to be awesome, but I'm not yet able to use it in production due to this issue.

jdthorpe avatar Sep 01 '25 14:09 jdthorpe

Any updates on this?

fdaciuk avatar Oct 11 '25 12:10 fdaciuk

move to astro

Lrmdom avatar Nov 04 '25 06:11 Lrmdom