-
Notifications
You must be signed in to change notification settings - Fork 822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expiration plugin throw error when cachedResponseWillBeUsed gets undefined as cachedResponse #1168
Comments
I'm having a similar issue in Workbox 3.0.0-alpha.4 I was trying workbox.routing.registerRoute(
/(.*)articles(.*)\.(?:png|gif|jpg)/,
workbox.strategies.cacheFirst({
cacheName: 'images-cache',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 50,
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days
}),
new workbox.cacheableResponse.Plugin({
statuses: [0, 200],
}),
]
})
); and getting the same error:
I first tried a generic operation to check that I wasn't just doing something weird: const testHandler = ({url, event}) => {
console.log(event);
};
workbox.routing.registerRoute(
/(.*)articles(.*)\.(?:png|gif|jpg)/,
testHandler
); which worked as expected. So then I removed the
which seems like it might be related. I'll dive into it a little more once I get to the office. |
Thanks for raising the issue - will take a look |
The cache expiration is a bug in Workbox. The request lifecycle can return null which the plugin was accounting for. PR has been raised to fix this. @DavidScales I'm not able to reproduce your error. Is there any chance you could send me an example site and / or a glitch.me example? |
Looks like glitch.me & I aren't getting along too well but I made a quickly stripped down version of the app. If you visit the hosted app, the service worker is installed and working. Then click on the link to "Article 1" (the erroneous route is for articles) and you should see the error in the console. The code is here for reference. |
potentially a silly question / not trying to sound impatient ;) - does this patch end up in 3.0.0-alpha.5 or is there another way for me to test it? |
@DavidScales you could run gulp build and host the file on your site and then in your service worker: importScripts(`<CDN URL>`);
importScripts(`/workbox-cache-expiration.dev.js`);
<rest of code here> That should result in the build being used instead of the CDN. |
@DavidScales the .5 release is now out with the fix. Would love to know if it fixed your problem. |
@gauntface thanks for the advice on the Currently looks like alpha.5 doesn't fix my error :( Commenting out the cacheableResponse plugin seems to work: workbox.routing.registerRoute(
/(.*)articles(.*)\.(?:png|gif|jpg)/,
workbox.strategies.cacheFirst({
cacheName: 'images-cache',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 50,
maxAgeSeconds: 30 * 24 * 60 * 60, // fixed in alpha.5
}),
/* still causing issues in alpha.5 */
// new workbox.cacheableResponse.Plugin({
// statuses: [0, 200],
// }),
]
})
); Also looks like it's only a problem when there is no image in the cache - if I comment out the This code is a bit above my level, but using the debugger it looks like the |
Moved discussion to: #1178 |
Library Affected:
Expiration plugin in workbox 3.0.0-alpha.3
Browser & Platform:
Version 63.0.3239.108 (Official Build) (64-bit)
Issue or Feature Request Description:
I am using expiration plugin as following:
For the first time the cachedResponseWillBeUsed gets undefined in the cachedResponse parameter and call to _isResponseDateFresh function with the undefined response.
In this function it tries to get a date property in the header of the response which is undefined.
Here is the console error I get:
The text was updated successfully, but these errors were encountered: