From 054b8a299274fafc61275b50374b4eb1e83e7e46 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 29 Nov 2020 01:29:34 +0100 Subject: [PATCH] fix: append to start_url without query param (fixes #403) --- src/workbox/options.ts | 7 ++++++- test/__snapshots__/pwa.test.js.snap | 4 ++-- test/fixture/nuxt.config.ts | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/workbox/options.ts b/src/workbox/options.ts index 6c4a0f0a..496ba7f5 100644 --- a/src/workbox/options.ts +++ b/src/workbox/options.ts @@ -73,7 +73,12 @@ export function getOptions (nuxt, pwa: PWAContext): WorkboxOptions { // Add start_url to precaching if (pwa.manifest && pwa.manifest.start_url) { - pwa.manifest.start_url += '&revision=' + options.cacheOptions.revision + const r = 'revision=' + options.cacheOptions.revision + if (pwa.manifest.start_url.includes('?')) { + pwa.manifest.start_url += '&' + r + } else { + pwa.manifest.start_url += '?' + r + } options.preCaching.unshift(...normalizePreCaching(pwa.manifest.start_url)) } diff --git a/test/__snapshots__/pwa.test.js.snap b/test/__snapshots__/pwa.test.js.snap index 34d57b50..3505c759 100644 --- a/test/__snapshots__/pwa.test.js.snap +++ b/test/__snapshots__/pwa.test.js.snap @@ -93,7 +93,7 @@ exports[`pwa manifest.json 1`] = ` \\"purpose\\": \\"any maskable\\" } ], - \\"start_url\\": \\"/?standalone=true\\", + \\"start_url\\": \\"/\\", \\"display\\": \\"standalone\\", \\"background_color\\": \\"#ffffff\\", \\"lang\\": \\"en\\", @@ -102,7 +102,7 @@ exports[`pwa manifest.json 1`] = ` `; exports[`pwa sw.js 1`] = ` -"const options = {\\"workboxURL\\":\\"https://cdn.jsdelivr.net/npm/workbox-cdn/workbox/workbox-sw.js\\",\\"importScripts\\":[\\"custom-sw.js\\"],\\"config\\":{\\"debug\\":true},\\"cacheNames\\":{\\"prefix\\":\\"test\\",\\"googleAnalytics\\":\\"test-ga\\"},\\"cacheOptions\\":{\\"revision\\":\\"test-rev\\",\\"cacheId\\":\\"@nuxtjs/pwa-prod\\"},\\"clientsClaim\\":true,\\"skipWaiting\\":true,\\"cleanupOutdatedCaches\\":true,\\"offlineAnalytics\\":true,\\"preCaching\\":[{\\"revision\\":\\"test-rev\\",\\"url\\":\\"/?standalone=true&revision=test-rev\\"},{\\"revision\\":\\"test-rev\\",\\"url\\":\\"precache.js\\"}],\\"runtimeCaching\\":[{\\"urlPattern\\":\\"https://google.com/.*\\",\\"handler\\":\\"CacheFirst\\",\\"method\\":\\"GET\\",\\"strategyPlugins\\":[]},{\\"urlPattern\\":\\"https://pwa.nuxtjs.org/.*\\",\\"handler\\":\\"CacheFirst\\",\\"method\\":\\"GET\\",\\"strategyOptions\\":{\\"cacheName\\":\\"nuxt-pwa\\"},\\"strategyPlugins\\":[{\\"use\\":\\"expiration.ExpirationPlugin\\",\\"config\\":[{\\"maxEntries\\":10,\\"maxAgeSeconds\\":300}]}]},{\\"urlPattern\\":\\"/_nuxt/\\",\\"handler\\":\\"CacheFirst\\",\\"method\\":\\"GET\\",\\"strategyPlugins\\":[]},{\\"urlPattern\\":\\"/\\",\\"handler\\":\\"NetworkFirst\\",\\"method\\":\\"GET\\",\\"strategyPlugins\\":[]}],\\"offlinePage\\":null,\\"pagesURLPattern\\":\\"/\\",\\"offlineStrategy\\":\\"NetworkFirst\\"} +"const options = {\\"workboxURL\\":\\"https://cdn.jsdelivr.net/npm/workbox-cdn/workbox/workbox-sw.js\\",\\"importScripts\\":[\\"custom-sw.js\\"],\\"config\\":{\\"debug\\":true},\\"cacheNames\\":{\\"prefix\\":\\"test\\",\\"googleAnalytics\\":\\"test-ga\\"},\\"cacheOptions\\":{\\"revision\\":\\"test-rev\\",\\"cacheId\\":\\"@nuxtjs/pwa-prod\\"},\\"clientsClaim\\":true,\\"skipWaiting\\":true,\\"cleanupOutdatedCaches\\":true,\\"offlineAnalytics\\":true,\\"preCaching\\":[{\\"revision\\":\\"test-rev\\",\\"url\\":\\"/?revision=test-rev\\"},{\\"revision\\":\\"test-rev\\",\\"url\\":\\"precache.js\\"}],\\"runtimeCaching\\":[{\\"urlPattern\\":\\"https://google.com/.*\\",\\"handler\\":\\"CacheFirst\\",\\"method\\":\\"GET\\",\\"strategyPlugins\\":[]},{\\"urlPattern\\":\\"https://pwa.nuxtjs.org/.*\\",\\"handler\\":\\"CacheFirst\\",\\"method\\":\\"GET\\",\\"strategyOptions\\":{\\"cacheName\\":\\"nuxt-pwa\\"},\\"strategyPlugins\\":[{\\"use\\":\\"expiration.ExpirationPlugin\\",\\"config\\":[{\\"maxEntries\\":10,\\"maxAgeSeconds\\":300}]}]},{\\"urlPattern\\":\\"/_nuxt/\\",\\"handler\\":\\"CacheFirst\\",\\"method\\":\\"GET\\",\\"strategyPlugins\\":[]},{\\"urlPattern\\":\\"/\\",\\"handler\\":\\"NetworkFirst\\",\\"method\\":\\"GET\\",\\"strategyPlugins\\":[]}],\\"offlinePage\\":null,\\"pagesURLPattern\\":\\"/\\",\\"offlineStrategy\\":\\"NetworkFirst\\"} importScripts(...[options.workboxURL, ...options.importScripts]) diff --git a/test/fixture/nuxt.config.ts b/test/fixture/nuxt.config.ts index 3941e4a6..73f590cb 100644 --- a/test/fixture/nuxt.config.ts +++ b/test/fixture/nuxt.config.ts @@ -17,6 +17,7 @@ export default { name: 'Test Project Name', description: 'Test Project Description', useWebmanifestExtension: true, + start_url: '/', fileName: 'manifest_test.[ext]?[hash]', orientation: 'portrait' },