Open kelvindecosta opened 1 year ago
I assume you're talking about dev server: we configure the entry point to avoid caching any resource, you're in dev mode and so the sw will intercept any request, any change made to the UI will not be updated.
Hey, thanks for the quick response!
I noticed that this is meant for development
only, but it seems to be affecting production
too.
Note To clarify what I meant about "previewing", I ran
pnpm build && pnpm preview
and checked the resulting local website.
Maybe it makes sense to run the following code only in development
?
+ if (import.meta.env.DEV) {
// to prevent service worker from intercepting requests in dev mode
registerRoute(new NavigationRoute(
createHandlerBoundToURL('/'),
{ allowlist },
))
+ }
@kelvindecosta then your app will not work when offline
EDIT: I mean, your service worker will work in both envs, createHandlerBoundToURL
will allow work offline (you'll need to add some logic) to avoid chrome dinossour for example... If you're using the sw only to cache assets previous code will work (you can also remove that route from the sw).
Thanks for the information!
To be completely clear, the app seems to work when in offline mode, after the above change. Here's what I've done:
pnpm build && pnpm preview
http://localhost:4173
in incognito modeOffline
modeThe app seems to be working fine.
Note
I only see the dinosaur for a split second when I
Hard Reload
orEmpty Cache and Hard Reload
. It immediately loads the app from the service worker (confirmed in theHeaders > General
)
Even the +server.ts
routes work fine.
By strictly following the example project code, the +error.svelte
pages and +server.ts
pages never get rendered, and are always redirected to home, by the sw.
I'm having the same issue using generateSW
#44. Is there a way to get this working with generateSW
?
Overview
When navigating to missing routes (
404
) within the example project, the home page (/
) is rendered instead.I've adopted almost the same configuration and service worker script for a personal project. I've noticed that the service worker even redirects server routes (
+server.ts
) to/
.Cause
I think that the issue lies within the following lines within the service worker script:
https://github.com/vite-pwa/sveltekit/blob/c6c34992a1cd5cec2bb58ea1ae82273c9308048c/examples/sveltekit-ts/src/prompt-sw.ts#L21-L29
When getting rid of these lines from my personal project, I no longer run into this issue.
404
error page+server.ts
routes behave as expectedConclusion
I would appreciate it if some more context could be added as to why these lines are required.
Thank you for your time.