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

VitePWA only caches "/" and (as a possible result) only renders index (/) when running middleware code. #56

Open
Timtendo12 opened this issue Jul 21, 2023 · 3 comments

Comments

@Timtendo12
Copy link

------------------------------
- Operating System: Windows_NT
- Node Version:     v18.16.0
- Nuxt Version:     3.6.5
- Nitro Version:    2.5.2
- Package Manager:  npm@9.8.0
- Builder:          vite
- User Config:      pages, ssr, debug, dev, modules, pwa, app, vue, ignore
- Runtime Modules:  @nuxt/devtools@0.2.5, @vite-pwa/nuxt
- Build Modules:    -
------------------------------
pwa: {
    registerType: "autoUpdate",
    manifest: {
      name: "HelpCenter",
      short_name: "HelpCenter",
      theme_color: "#35B05F",
      background_color: "#FFFFFF",
      icons: [
        {
          src: "/img/pwa-192x192.png",
          sizes: "192x192",
          type: "image/png",
        },
        {
          src: "/img/pwa-512x512.png",
          sizes: "512x512",
          type: "image/png",
        },
      ],
    },
      workbox: {
        navigateFallback: "/",
          globPatterns: ["**!/!*.{js,css,html,ico,png,jpg,jpeg,svg}"],
      },
    devOptions: {
      enabled: true,
      type: "module",
    },
  }

Since i've updated my nuxt version VitePWA/Nuxt acts very weird.

It only caches "/" instead of every (possible) route, spams alot of errors in console

image

Errors in console
image

As a result it also renders the index "/" whenever nuxt runs middleware code. resulting in flashes when navigating. Sometimes it even wont allow me to navigate to other pages. I see the url changing but before it even renders the page it returns to the index

image

Completly disbaling the plugin fixes these issues. I hope you'll take a look into it!

@userquin
Copy link
Member

@Timtendo12 The plugin in dev will intercept only the entry point as you can see in your last screenshot, about the errors from background.js module you should check what's happening.

In elk.zone gh repo we use a middleware and the index page is using it, the page is empty, the middleware always navigate to another page: https://github.com/elk-zone/elk/blob/main/middleware/auth.ts

@Onyoursix
Copy link

Onyoursix commented Jul 28, 2023

I upgraded from 0.0.7 to 0.1.0 and I have this exact same issue in dev mode. Reloading (or going direct) localhost:3000/LiterallyAnyPageHere to see changes being worked on will redirect me to /. Even more strange is if there's a query in the url localhost:3000/LiterallyAnyPageHere?c=something it will redirect me localhost:3000?c=something.

This has me scratching my head, because even when I downgrade back to 0.0.7, unregister the server worker, delete cache etc. The problem STILL persists. I'm at a loss on this issue. Disabling the plugin does "fix" the issue.

No idea if this screen shot helps, mainly did it because OP did. There are no errors in my console or messages, just redirects as if it's hard programmed into every page.

image

@Onyoursix
Copy link

Just an update, I found a fix for this.

When I manually added strategies: 'generateSW', to my nuxt.confit.ts pwa settings that seemed to fix it. I know that's supposed to be the default mode, but manually adding it seems to fix my issue. Here are my pwa config settings

    pwa: {
        strategies: 'generateSW',
        registerType: 'autoUpdate',
        manifest: {
            name: "myApp",
            short_name: "myApp",
            description: "myApp",
            theme_color: "#00d6e6",
            icons: [
                {
                    src: "img/icons/apple-touch-icon-76x76.png",
                    sizes: "64x64",
                    type: 'image/png'
                },
                {
                    src: "img/icons/apple-touch-icon-152x152.png",
                    sizes: "144x144",
                    type: 'image/png'
                },
                {
                    src: "img/icons/apple-touch-icon-180x180.png",
                    sizes: "180x180",
                    type: 'image/png'
                },
                {
                    src: "img/icons/android-chrome-192x192.png",
                    sizes: "192x192",
                    type: 'image/png'
                },
                {
                    src: "img/icons/android-chrome-512x512.png",
                    sizes: "512x512",
                    type: 'image/png'
                }
            ]
        },
        workbox: {
            navigateFallback: '/',
            globPatterns: ['**/*.{js,css,html,png,svg,ico}'],            
        },
        devOptions: {
            enabled: true,           
            navigateFallbackAllowlist: [/^\/$/],
            type: 'module',
        }
    },

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

No branches or pull requests

3 participants