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

Vue 3/VitePWA - autoUpdate - not reloading page #438

Closed
crunchwrap89 opened this issue Dec 30, 2022 · 18 comments
Closed

Vue 3/VitePWA - autoUpdate - not reloading page #438

crunchwrap89 opened this issue Dec 30, 2022 · 18 comments

Comments

@crunchwrap89
Copy link

"vue": "^3.2.45",
"vite": "^4.0.1",
"vite-plugin-pwa": "^0.14.0",

with below settings in vite.config.ts, my service worker is currently automatically downloading the new version in the background, but it is not automatically reloading the page to show the new version.

  registerType: "autoUpdate",
  workbox: {
    clientsClaim: true,
    skipWaiting: true,
    globPatterns: [
      "**/*.{js,css,html,ico,png,jpg,jpeg,svg,webp,wav,mp3,gltf,bin,eot,ttf,woff,woff2}",
    ],
    maximumFileSizeToCacheInBytes: 25097152,
  },
  includeAssets: [
   ...
  ],

....

Currently i must manually reload the page for the new version to take effect.
I have tried it in multiple types of browsers and devices. Same issue on all.

What might be the reason to the page not being automatically reloaded?
I checked the documentation and according to them it should automatically reload when registerType is on autoUpdate?
I tried adding clientsClaim: true, and skipWaiting: true, but still the same issue.

vitePWA

@userquin
Copy link
Member

@crunchwrap89 what's your full pwa configuration file?

@crunchwrap89
Copy link
Author

crunchwrap89 commented Jan 1, 2023

@userquin

    VitePWA({
      registerType: "autoUpdate",
      workbox: {
        clientsClaim: true,
        skipWaiting: true,
        globPatterns: [
          "**/*.{js,css,html,ico,png,jpg,jpeg,svg,webp,wav,mp3,gltf,bin,eot,ttf,woff,woff2}",
        ],
        maximumFileSizeToCacheInBytes: 25097152,
      },
      includeAssets: [
        "favicon.ico",
        "assets/icons/icon-180x180.png",
        "assets/icons/logo.svg",
      ],
      manifest: {
        name: "MapCanvas3D",
        short_name: "MapCanvas3D",
        description: "An interactive 3D Map Canvas.",
        id: "https://mapcanvas3d.com/",
        theme_color: "#022029",
        background_color: "#022029",
        icons: [
          {
            src: "assets/icons/windows11/SmallTile.scale-100.png",
            sizes: "71x71",
          },
          {
            src: "assets/icons/windows11/SmallTile.scale-125.png",
            sizes: "89x89",
          },
          {
            src: "assets/icons/windows11/SmallTile.scale-150.png",
            sizes: "107x107",
          },
          {
            src: "assets/icons/windows11/SmallTile.scale-200.png",
            sizes: "142x142",
          },
          {
            src: "assets/icons/windows11/SmallTile.scale-400.png",
            sizes: "284x284",
          },
          {
            src: "assets/icons/windows11/Square150x150Logo.scale-100.png",
            sizes: "150x150",
          },
          {
            src: "assets/icons/windows11/Square150x150Logo.scale-125.png",
            sizes: "188x188",
          },
          {
            src: "assets/icons/windows11/Square150x150Logo.scale-150.png",
            sizes: "225x225",
          },
          {
            src: "assets/icons/windows11/Square150x150Logo.scale-200.png",
            sizes: "300x300",
          },
          {
            src: "assets/icons/windows11/Square150x150Logo.scale-400.png",
            sizes: "600x600",
          },
          {
            src: "assets/icons/windows11/Wide310x150Logo.scale-100.png",
            sizes: "310x150",
          },
          {
            src: "assets/icons/windows11/Wide310x150Logo.scale-125.png",
            sizes: "388x188",
          },
          {
            src: "assets/icons/windows11/Wide310x150Logo.scale-150.png",
            sizes: "465x225",
          },
          {
            src: "assets/icons/windows11/Wide310x150Logo.scale-200.png",
            sizes: "620x300",
          },
          {
            src: "assets/icons/windows11/Wide310x150Logo.scale-400.png",
            sizes: "1240x600",
          },
          {
            src: "assets/icons/windows11/LargeTile.scale-100.png",
            sizes: "310x310",
          },
          {
            src: "assets/icons/windows11/LargeTile.scale-125.png",
            sizes: "388x388",
          },
          {
            src: "assets/icons/windows11/LargeTile.scale-150.png",
            sizes: "465x465",
          },
          {
            src: "assets/icons/windows11/LargeTile.scale-200.png",
            sizes: "620x620",
          },
          {
            src: "assets/icons/windows11/LargeTile.scale-400.png",
            sizes: "1240x1240",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.scale-100.png",
            sizes: "44x44",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.scale-125.png",
            sizes: "55x55",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.scale-150.png",
            sizes: "66x66",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.scale-200.png",
            sizes: "88x88",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.scale-400.png",
            sizes: "176x176",
          },
          {
            src: "assets/icons/windows11/StoreLogo.scale-100.png",
            sizes: "50x50",
          },
          {
            src: "assets/icons/windows11/StoreLogo.scale-125.png",
            sizes: "63x63",
          },
          {
            src: "assets/icons/windows11/StoreLogo.scale-150.png",
            sizes: "75x75",
          },
          {
            src: "assets/icons/windows11/StoreLogo.scale-200.png",
            sizes: "100x100",
          },
          {
            src: "assets/icons/windows11/StoreLogo.scale-400.png",
            sizes: "200x200",
          },
          {
            src: "assets/icons/windows11/SplashScreen.scale-100.png",
            sizes: "620x300",
          },
          {
            src: "assets/icons/windows11/SplashScreen.scale-125.png",
            sizes: "775x375",
          },
          {
            src: "assets/icons/windows11/SplashScreen.scale-150.png",
            sizes: "930x450",
          },
          {
            src: "assets/icons/windows11/SplashScreen.scale-200.png",
            sizes: "1240x600",
          },
          {
            src: "assets/icons/windows11/SplashScreen.scale-400.png",
            sizes: "2480x1200",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.targetsize-16.png",
            sizes: "16x16",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.targetsize-20.png",
            sizes: "20x20",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.targetsize-24.png",
            sizes: "24x24",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.targetsize-30.png",
            sizes: "30x30",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.targetsize-32.png",
            sizes: "32x32",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.targetsize-36.png",
            sizes: "36x36",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.targetsize-40.png",
            sizes: "40x40",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.targetsize-44.png",
            sizes: "44x44",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.targetsize-48.png",
            sizes: "48x48",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.targetsize-60.png",
            sizes: "60x60",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.targetsize-64.png",
            sizes: "64x64",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.targetsize-72.png",
            sizes: "72x72",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.targetsize-80.png",
            sizes: "80x80",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.targetsize-96.png",
            sizes: "96x96",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.targetsize-256.png",
            sizes: "256x256",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-unplated_targetsize-16.png",
            sizes: "16x16",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-unplated_targetsize-20.png",
            sizes: "20x20",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-unplated_targetsize-24.png",
            sizes: "24x24",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-unplated_targetsize-30.png",
            sizes: "30x30",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-unplated_targetsize-32.png",
            sizes: "32x32",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-unplated_targetsize-36.png",
            sizes: "36x36",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-unplated_targetsize-40.png",
            sizes: "40x40",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-unplated_targetsize-44.png",
            sizes: "44x44",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-unplated_targetsize-48.png",
            sizes: "48x48",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-unplated_targetsize-60.png",
            sizes: "60x60",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-unplated_targetsize-64.png",
            sizes: "64x64",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-unplated_targetsize-72.png",
            sizes: "72x72",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-unplated_targetsize-80.png",
            sizes: "80x80",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-unplated_targetsize-96.png",
            sizes: "96x96",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-unplated_targetsize-256.png",
            sizes: "256x256",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-lightunplated_targetsize-16.png",
            sizes: "16x16",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-lightunplated_targetsize-20.png",
            sizes: "20x20",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-lightunplated_targetsize-24.png",
            sizes: "24x24",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-lightunplated_targetsize-30.png",
            sizes: "30x30",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-lightunplated_targetsize-32.png",
            sizes: "32x32",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-lightunplated_targetsize-36.png",
            sizes: "36x36",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-lightunplated_targetsize-40.png",
            sizes: "40x40",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-lightunplated_targetsize-44.png",
            sizes: "44x44",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-lightunplated_targetsize-48.png",
            sizes: "48x48",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-lightunplated_targetsize-60.png",
            sizes: "60x60",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-lightunplated_targetsize-64.png",
            sizes: "64x64",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-lightunplated_targetsize-72.png",
            sizes: "72x72",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-lightunplated_targetsize-80.png",
            sizes: "80x80",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-lightunplated_targetsize-96.png",
            sizes: "96x96",
          },
          {
            src: "assets/icons/windows11/Square44x44Logo.altform-lightunplated_targetsize-256.png",
            sizes: "256x256",
          },
          {
            src: "assets/icons/android/android-launchericon-512-512.png",
            sizes: "512x512",
          },
          {
            src: "assets/icons/android/android-launchericon-192-192.png",
            sizes: "192x192",
          },
          {
            src: "assets/icons/android/android-launchericon-144-144.png",
            sizes: "144x144",
          },
          {
            src: "assets/icons/android/android-launchericon-96-96.png",
            sizes: "96x96",
          },
          {
            src: "assets/icons/android/android-launchericon-72-72.png",
            sizes: "72x72",
          },
          {
            src: "assets/icons/android/android-launchericon-48-48.png",
            sizes: "48x48",
          },
          {
            src: "assets/icons/ios/16.png",
            sizes: "16x16",
          },
          {
            src: "assets/icons/ios/20.png",
            sizes: "20x20",
          },
          {
            src: "assets/icons/ios/29.png",
            sizes: "29x29",
          },
          {
            src: "assets/icons/ios/32.png",
            sizes: "32x32",
          },
          {
            src: "assets/icons/ios/40.png",
            sizes: "40x40",
          },
          {
            src: "assets/icons/ios/50.png",
            sizes: "50x50",
          },
          {
            src: "assets/icons/ios/57.png",
            sizes: "57x57",
          },
          {
            src: "assets/icons/ios/58.png",
            sizes: "58x58",
          },
          {
            src: "assets/icons/ios/60.png",
            sizes: "60x60",
          },
          {
            src: "assets/icons/ios/64.png",
            sizes: "64x64",
          },
          {
            src: "assets/icons/ios/72.png",
            sizes: "72x72",
          },
          {
            src: "assets/icons/ios/76.png",
            sizes: "76x76",
          },
          {
            src: "assets/icons/ios/80.png",
            sizes: "80x80",
          },
          {
            src: "assets/icons/ios/87.png",
            sizes: "87x87",
          },
          {
            src: "assets/icons/ios/100.png",
            sizes: "100x100",
          },
          {
            src: "assets/icons/ios/114.png",
            sizes: "114x114",
          },
          {
            src: "assets/icons/ios/120.png",
            sizes: "120x120",
          },
          {
            src: "assets/icons/ios/128.png",
            sizes: "128x128",
          },
          {
            src: "assets/icons/ios/144.png",
            sizes: "144x144",
          },
          {
            src: "assets/icons/ios/152.png",
            sizes: "152x152",
          },
          {
            src: "assets/icons/ios/167.png",
            sizes: "167x167",
          },
          {
            src: "assets/icons/ios/180.png",
            sizes: "180x180",
          },
          {
            src: "assets/icons/ios/192.png",
            sizes: "192x192",
          },
          {
            src: "assets/icons/ios/256.png",
            sizes: "256x256",
          },
          {
            src: "assets/icons/ios/512.png",
            sizes: "512x512",
            purpose: "any maskable",
          },
          {
            src: "assets/icons/ios/1024.png",
            sizes: "1024x1024",
          },
        ],
      },
    }),

@Timonzimm
Copy link

Timonzimm commented Jan 2, 2023

I'm having exactly the same issue here.

I have to manually refresh the page with hard reload. And on my phone it's a bit more annoying as emptying the cache is not as easy.

    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "vite": "^4.0.0",
    "vite-plugin-pwa": "^0.14.0"

@userquin
Copy link
Member

userquin commented Jan 2, 2023

so, the sw keeps on yellow state (skip waiting), I'll check it, I have tested it only on desktop...

@userquin
Copy link
Member

userquin commented Jan 2, 2023

upps, ok, we should merge pending PR #428

@crunchwrap89
Copy link
Author

@userquin i updated to 14.1 and unfortunately it still doesn't reload the page automatically after new version is downloaded.
Checked on multiple devices

@userquin
Copy link
Member

userquin commented Jan 3, 2023

@crunchwrap89 check #377

#377 (comment)

@crunchwrap89
Copy link
Author

@crunchwrap89 check #377

#377 (comment)

Ah yes, adding below code to the main.ts file solved the issue. It now reloads the page automatically after update was downloaded.

import { registerSW } from 'virtual:pwa-register'

registerSW({ immediate: true })

Can this solution be added to the documentation on https://vite-pwa-org.netlify.app/guide/auto-update.html ?
If you need any help i would love to contribute?

@userquin
Copy link
Member

userquin commented Jan 3, 2023

Pr welcome, send it to docs repo

@crunchwrap89
Copy link
Author

i will fork and create PR tomorrow

@userquin
Copy link
Member

userquin commented Jan 7, 2023

@crunchwrap89
Copy link
Author

Awesome, now its more clear. :) Sorry i didnt make the pr myself, I am sick and dont have energy to do it yet.

There is also another warning or hint that could be added to docs: public assets such as robots.txt, sitemap.xml and even manifest.webmanifest should be added to includeAssets in the vitePWA plugin options.

Otherwise service worker will serve 404 page route instead.

@userquin
Copy link
Member

userquin commented Jan 7, 2023

@crunchwrap89 PR welcome: robots.txt and sitemap.xml not necessary to be included, both only used by crawlers. There is no problem adding them to the sw precache manifest.

@mustafadalga
Copy link

Hi @userquin ,

While the old version files are deleted and the new version's files are processed, if you refresh the page and switch between pages, it throws the following error because it cannot find the old javascript files.

At the same time, the automatic reload doesn't work because it throws this error.

TypeError: Failed to fetch dynamically imported module:

Error screenshot

screenshot-1

screenshot-2

Error video

video.mp4

Demo link: https://vue-router-3.d2y8hqcamgs1js.amplifyapp.com/
Minimal project repo : https://github.com/mustafadalga/vite-plugin-pwa-vue-basic-project/tree/vue-router-3

vite.config.ts

export default defineConfig(({command, mode}: IDefineConfig) => {

    const configs = {
        plugins: [
            VitePWA({
                // @ts-ignore
                mode: mode,
                registerType: "autoUpdate",
                useCredentials: true,
                workbox:{
                    maximumFileSizeToCacheInBytes:3000000
                },
            })
        ],
        build: {
            rollupOptions: {
                output: {
                    assetFileNames: (assetInfo: IAssetFileNames) => {
                        const extType: string = assetInfo.name.split(".")[1];
                        return `assets/${extType}/[name][extname]`;
                    },
                    chunkFileNames: "assets/js/[name]-[hash].js"

                }
            }
        },

    }

    return configs;
});

main.ts

import { createApp } from 'vue'
import { createRouter, createWebHistory } from 'vue-router'
import App from './App.vue'
import { registerSW } from 'virtual:pwa-register';

registerSW({ immediate: true });


const router = createRouter({
    history: createWebHistory(),
    routes: [
        {path: '/', component: () => import('./pages/home.vue')},
        {path: '/about', component: () => import('./pages/about.vue')},
        {path: '/contact', component: () => import('./pages/Contact.vue')},
        {path: '/dashboard', component: () => import('./pages/Dashboard.vue')},
        {path: '/dashboard-v2', component: () => import('./pages/DashboardV2.vue')},
        {path: '/dashboard-v3', component: () => import('./pages/DashboardV3.vue')},
        {path: '/dashboard-v4', component: () => import('./pages/DashboardV4.vue')},
        {path: '/profile', component: () => import('./pages/Profile.vue')},
        {path: '/my-insights', component: () => import('./pages/MyInsights.vue')},
        {path: '/gallery', component: () => import('./pages/Gallery.vue')},
        {path: '/hi/:name', component: () => import('./pages/hi/[name].vue'), props: true},
        {path: "/:catchAll(.*)", component: () => import('./pages/NotFound.vue')},
    ],
})

createApp(App).use(router).mount('#app')

Package versions

    "vue": "^3.2.45",
    "vite": "^4.0.0",
    "vite-plugin-pwa": "^0.14.1"

Server : Amplify

@sergeushenecz
Copy link

I have same problem. Page not reload.

@zyxkad
Copy link

zyxkad commented Feb 25, 2024

I've met the same problem, but after I tried, I found that's because I did:

export default VitePWA({
	registerType: 'autoUpdate',
	injectRegister: 'inline',
})

However, because I also used import { registerSW } from 'virtual:pwa-register', the ServiceWorker actually register twice, and the inline one overrided the virtual package one, so it did not automatically reload.

The solution is set injectRegister to null or 'auto'

@zyxkad
Copy link

zyxkad commented Feb 25, 2024

@userquin Please add this notice to the doc, so people won't be dumb

@ConstantinFF
Copy link

I've met the same problem, but after I tried, I found that's because I did:

export default VitePWA({
	registerType: 'autoUpdate',
	injectRegister: 'inline',
})

However, because I also used import { registerSW } from 'virtual:pwa-register', the ServiceWorker actually register twice, and the inline one overrided the virtual package one, so it did not automatically reload.

The solution is set injectRegister to null or 'auto'

I got the same issue. Your solution worked.

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

7 participants