shadowwalker / next-pwa

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

Non-stop refresh on offline mode #498

Closed NavidNourani closed 5 months ago

NavidNourani commented 7 months ago

Summary

I'm using Next-PWA and Next-translate

I used middleware to support multi-tenant (middleware rewrites user's requests to it's organization's page) it's the abridged version of the middleware:

export async function middleware(req: NextRequest) {
    const url = req.nextUrl.clone();
    url.pathname = `/organizations/${viewport}/${req.headers.get('host')}${url.pathname}`;
    return NextResponse.rewrite(url);
}

We wanted to cache the viewport, organization(host), and the path.

The point is that next-translate rewrite request to its language (If we don't specify any languages it sends the user to /default language)

And the problem is that in offline mode when we can see the cached root page it tries to get the default page and it causes a non-stop refresh on the page.

I set dynamicStartUrlRedirect: '/default' in PWA config I tried additionalManifestEntries too Actually, it cached the default page but doesn't use it! In the online mode: image

In the offline mode(With non-stop refresh): image

Here is the cached page: image

Versions

NavidNourani commented 7 months ago

I changed the Next version to 12.3.2 and it works fine now!

codespearhead commented 5 months ago

@NavidNourani Can you please close this issue then?