-
Notifications
You must be signed in to change notification settings - Fork 828
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
Throw a WorkboxError when cacheExpiration is used without cacheName #1079
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing that we may still face is that if the developer uses the plugin outside of this builder, the error will not throw.
registerRoute(new RegExp(...), strategies.cacheFirst({
plugins: [
new expiration.CacheExpirationPlugin()
]
}))
Should we add a check to: https://github.com/GoogleChrome/workbox/blob/v3/packages/workbox-cache-expiration/CacheExpirationPlugin.mjs#L114 before treating the issue as fixed?
I think adding the check there before we call this fully good would be useful. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I'm going to revisit this PR once #1084 lands. |
Feel free to re-explore now that #1084 has landed |
I do not believe that the
My inclination is that if we were to detect this sort of thing at runtime, it should be a warning rather than a fatal error. But my preference would be to keep the original approach of throwing a fatal error when the strategy is misconfigured ahead of time vs. a warning at runtime. How do other folks feel about those options? |
For dev we could a check of: 'If no cache name and a plugin of type "expiration.Plugin", throw an error' and for prod, throw at runtime. |
I know that this was already approved, but I've made changes along the lines of #1079 (comment) and it would be great to have it looked over again prior to merging. |
@@ -56,6 +58,15 @@ const mapping = { | |||
const defaultExport = {}; | |||
Object.keys(mapping).forEach((keyName) => { | |||
defaultExport[keyName] = (options = {}) => { | |||
if (process.env.NODE_ENV !== 'production') { | |||
if (options.cacheExpiration && !options.cacheName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't needed anymore as the cacheExpiration option doesn't get used - developers have to explicitly create the Plugin.
devOnly.it(`should throw when cacheExpiration is used without cacheName`, async function() { | ||
await expectError( | ||
() => strategies.cacheFirst({ | ||
cacheExpiration: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like wise - this test should be failing since this option does nothing now.
@@ -86,6 +88,13 @@ class Plugin { | |||
* @private | |||
*/ | |||
_getCacheExpiration(cacheName) { | |||
if (cacheName === cacheNames.getRuntimeName()) { | |||
throw new WorkboxError('cache-expiration-requires-cache-name', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Maybe this error code should be 'expire-custom-caches-only'
throw new Error(`Unexpected input to 'cache-expiration-requires-cache` + | ||
`-name' error.`); | ||
} | ||
return `You must also configure 'cacheName' when using 'cacheExpiration' ` + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This message should be changed to something like You must provide a 'cacheName' property when using the expiration Plugin with a strategy.
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this branch needs updating with the latest strategy code since the cacheExpiration option isn't used anymore.
PR-Bot Size PluginChanged File Sizes
New FilesNo new files have been added. All File SizesView Table
Workbox Aggregate Size Plugin☠️ WARNING ☠️We are using 152% of our max size budget. Total Size: 22.25KB Gzipped: 8.85KB |
Unless I've missed something else obvious, this should have the required changes now, @gauntface. Thanks for your patience. |
R: @addyosmani @gauntface
Fixes #1014
I don't know what the criteria is for doing this sort of thing in
NODE_ENV !== 'production'
vs. unconditionally, but I went with unconditionally.