Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(experimental): add includeAllowlist for generateSW strategy #108

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

userquin
Copy link
Member

@userquin userquin commented Dec 20, 2023

This PR allows deal with missing and SSR pages for generateSW strategy, can be used via Nuxt generate or build commands, it is similar to this one for VP vite-pwa/vitepress#23:

  • for generate command, the module will use 404 prerendered page when requesting a missing page: when online, the server will send 404 and client app will be forwarded to error page, when offline, the runtime caching will redirect to 404 (the page must be in the sw precache manifest) and the client app will be forwarded to error page but with 404 in the address bar
  • for build command, the sw will have the same behavior described requesting missing pages also for SSR pages.

✔️ I need to update Vitest and add Playwright offline tests, added in pwa plugin repo.

There is a bug in Playwright and chromium about offline and service workers, it is not working, this expectation is failing:
https://github.com/vite-pwa/nuxt/pull/108/files#diff-4582f966059acac2f5f0f43eb765b42d4c0e39911f5aef7828cf4728a9ca2977R45

To test the new experimental allow list feature:

  • from root run pnpm install && nr prepack
  • nuxi generate
    • from root, nr test:generate:allowlist && pnpm server playground/dist
    • open browser and navigate to /missing: should forward to /missing with 404 page
    • go offline in network tab and refresh missing page: should redirect to /404 with 404 page
    • go online, back to home and enter some text in the input, click GO button and refresh page, should work
    • go offline and refresh hi page, should redirect to /404 with 404 page
  • nuxi build
    • from root, nr test:build:allowlist && && node playground/.output/server/index.mjs
    • open browser and navigate to /missing: should forward to /missing with 404 page
    • go offline in network tab and refresh missing page: should redirect to /
    • go online, back to home and enter some text in the input, click GO button and refresh page, should work
    • go offline and refresh hi page, should redirect to /

In both cases, hi route should work when offline and navigate via GO button.

This feature is about avoid offline browser page, you can configure a custom page for the redirection when offline.

/cc @danielroe @antfu sorry guys, this PR is quite simple compared to #66, I'll check it with vitesse-nuxt and hi route, here we don't have any dynamic route (maybe we should add a simple hi SSR page 😅 )

supersedes #66

@userquin userquin marked this pull request as draft December 20, 2023 23:31
@userquin userquin marked this pull request as ready for review December 21, 2023 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant