shadowwalker / next-pwa

Zero config PWA plugin for Next.js, with workbox 🧰
MIT License
3.75k stars 311 forks source link

cacheOnFrontEndNav stop working for next/link #428

Open darkkatarsis opened 1 year ago

darkkatarsis commented 1 year ago

Summary

I noticed that at some point the fallback to the offline page stopped working. I was able to debug that the anomaly only occurs when using next/link. I.e. the fallback itself "kinda works" (but it kinda doesn't reload the page and you don't see the offline page just an error on the client side. A hard reset loads the offline page). If we use a regular link or other link type component the problem is not there.

Versions

How To Reproduce

Just use next/link and enter offline mode to try to load the fallback

Expected Behaviors

Working offline fallback for next/link

Screenshots

Screenshot 2022-11-07 at 20 27 59

Additional Context

next.config.mjs:

import runtimeCaching from 'next-pwa/cache.js';
import i18next from './next-i18next.config.js';
import nextPWA from 'next-pwa';

const withPWA = nextPWA({
    disable: process.env.NODE_ENV === 'development',
    dest: 'public',
    cacheOnFrontEndNav: true,
    skipWaiting: true,
    runtimeCaching,
    fallbacks: {
        document: '/offline',
    },
});

const config = {
    i18n: i18next.i18n,
    images: {
        domains: ['googleusercontent.com'],
        formats: ['image/avif', 'image/webp'],
        minimumCacheTTL: 31536000,
    },
    reactStrictMode: true,
};

export default withPWA(config);
shadowwalker commented 1 year ago

Offline fallback is not what you think it is. Offline fallback is when user lost network connectivity and try to visit a link on your web app not cached locally before, then fallback to the page.