GoogleChrome / workbox

📦 Workbox: JavaScript libraries for Progressive Web Apps
https://developers.google.com/web/tools/workbox/
MIT License
12.3k stars 811 forks source link

Workbox is not returning the cached page following a 303 redirect after a POST response #3350

Closed frederikhors closed 4 weeks ago

frederikhors commented 4 weeks ago

I have this workbox service worker setup:

importScripts('https://storage.googleapis.com/workbox-cdn/releases/7.1.0/workbox-sw.js');

workbox.routing.registerRoute(
    ({ url }) => !url.pathname.includes("."),
    new workbox.strategies.StaleWhileRevalidate(),
);

self.skipWaiting();

workbox.core.clientsClaim();

and it is working very good!

Now I have a page with a form to add a new todo: /todos/new with a simple <form method="post"> in it.

After the POST request the server returns a redirect 303 - /todods.

In the browser (Chrome) I can clearly see the POST /todos/new request with the redirect response and a new request GET /todos.

The issue is that the GET /todos is not handled by Workbox.

I expect it to serve the cached version of /todos (is already in cache of course).

For example, for the others GET requests (/todos included) I get in the browser console messages from Workbox like this:

workbox Router is responding to: /
workbox Router is responding to: /todos

but for the GET /todos after the POST /todos/new workbox is not stepping in.

Why?

frederikhors commented 4 weeks ago

It was an XHR issue.