next-pwa icon indicating copy to clipboard operation
next-pwa copied to clipboard

_offline page flashes briefly when loading dynamic route with query parameter

Open jamesopti opened this issue 3 years ago • 1 comments
trafficstars

Summary

I'm trying to debug why the _offline page I have flashes momentarily when loading a cached page without a network connection.

The start Url is / The page I'm testing is /docs/[docId]?foo=bar

Works fine: /docs/[docId] Flashes _offline: /docs/[docId]?foo=bar

Versions

  • next-pwa: next-pwa@npm:5.6.0
  • next: next@npm:12.2.5

jamesopti avatar Oct 27 '22 04:10 jamesopti

UPDATE:

This seems to have solved the issue for us, caching all requests to our /docs/[docId] page in the same key. Would love any input on this approach.

{
    urlPattern: ({ url }) => {
      const isSameOrigin = self.origin === url.origin
      if (!isSameOrigin) return false
      const pathname = url.pathname
      if (pathname.startsWith('/docs/')) return true
      return false
    },
    handler: 'NetworkFirst',
    options: {
      cacheName: 'docs',
      expiration: {
        maxEntries: 32,
        maxAgeSeconds: SEVEN_DAYS,
      },
      networkTimeoutSeconds: 10,
      plugins: [{ cacheKeyWillBeUsed: async () => '/docs' }],
    },
  },

jamesopti avatar Oct 27 '22 17:10 jamesopti