Skip to content
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

Expose the event object to plugin methods #1640

Merged
merged 4 commits into from Sep 18, 2018
Merged

Conversation

philipwalton
Copy link
Member

Fixes #1639.

This PR implements the proposal in #1639 by updating the fetch and catch wrappers as well as the strategies (and other code) that calls them. It also removes the preloadResponse option passed to the fetch wrapper, since that can now be found on the fetch event (@jeffposnick can you confirm that's okay?).

In addition, I noticed we're being inconsistent in how we refer to restructured parameters in our JSDoc comments (options vs input), so, since I was already updating some, I decided to change all instances of input to options.

@coveralls
Copy link

coveralls commented Sep 18, 2018

Coverage Status

Coverage increased (+0.03%) to 86.148% when pulling 307cc7f on plugins-events into 685fd1b on master.

@philipwalton
Copy link
Member Author

It's too bad that destructured params increase the file size so much...

Copy link
Contributor

@jeffposnick jeffposnick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are also some changes that will need to made to https://developers.google.com/web/tools/workbox/guides/using-plugins#custom_plugins in a separate PR to reflect the new plugin parameters.

* @param {Request} options.request
* @param {Response} options.response
* @param {Event} [options.event]
* @param {Array} [options.plugins=[]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{Array<Object>} for consistency.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

request,
event,
fetchOptions,
preloadResponse,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preloadResponse should be removed here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@jeffposnick
Copy link
Contributor

It's too bad that destructured params increase the file size so much...

I guess that could be why Matt wanted us to avoid them in the core libraries 😄

This might be the case of something that gets transpiled into bloated code when we need to support older browsers, and once we change our @babel/preset-env config in an upcoming v4 release, we'll stop paying the penalty? If you did a comparison of the bundle size in this PR for the current @babel/preset-env config and then again with a more recent browser target, what does that size delta look like?

@philipwalton
Copy link
Member Author

There are also some changes that will need to made to https://developers.google.com/web/tools/workbox/guides/using-plugins#custom_plugins in a separate PR to reflect the new plugin parameters.

Yes, but I'm assuming that should wait until the next release, right?

@workbox-pr-bot
Copy link
Collaborator

PR-Bot Size Plugin

Changed File Sizes

File Before After Change GZipped
packages/workbox-core/build/workbox-core.prod.js 7.19 KB 7.47 KB +4% 2.90 KB
packages/workbox-precaching/build/workbox-precaching.prod.js 5.57 KB 5.81 KB +4% 2.24 KB
packages/workbox-strategies/build/workbox-strategies.prod.js 4.52 KB 5.09 KB +13% 1.24 KB ☠️
packages/workbox-streams/build/workbox-streams.prod.js 1.57 KB 1.66 KB +6% 765 B

New Files

No new files have been added.

All File Sizes

View Table
File Before After Change GZipped
packages/workbox-background-sync/build/workbox-background-sync.prod.js 3.51 KB 3.51 KB 0% 1.45 KB
packages/workbox-broadcast-cache-update/build/workbox-broadcast-cache-update.prod.js 1.12 KB 1.12 KB 0% 584 B
packages/workbox-build/build/_types.js 41 B 41 B 0% 61 B
packages/workbox-build/build/index.js 4.02 KB 4.02 KB 0% 1.57 KB
packages/workbox-cache-expiration/build/workbox-cache-expiration.prod.js 3.89 KB 3.89 KB 0% 1.37 KB
packages/workbox-cacheable-response/build/workbox-cacheable-response.prod.js 587 B 587 B 0% 346 B
packages/workbox-cli/build/app.js 6.76 KB 6.76 KB 0% 2.27 KB
packages/workbox-cli/build/bin.js 2.32 KB 2.32 KB 0% 1.03 KB
packages/workbox-core/build/workbox-core.prod.js 7.19 KB 7.47 KB +4% 2.90 KB
packages/workbox-google-analytics/build/workbox-google-analytics.prod.js 2.12 KB 2.12 KB 0% 1.03 KB
packages/workbox-navigation-preload/build/workbox-navigation-preload.prod.js 522 B 522 B 0% 298 B
packages/workbox-precaching/build/workbox-precaching.prod.js 5.57 KB 5.81 KB +4% 2.24 KB
packages/workbox-range-requests/build/workbox-range-requests.prod.js 1.63 KB 1.63 KB 0% 798 B
packages/workbox-routing/build/workbox-routing.prod.js 2.87 KB 2.87 KB 0% 1.31 KB
packages/workbox-strategies/build/workbox-strategies.prod.js 4.52 KB 5.09 KB +13% 1.24 KB ☠️
packages/workbox-streams/build/workbox-streams.prod.js 1.57 KB 1.66 KB +6% 765 B
packages/workbox-sw/build/workbox-sw.js 1.50 KB 1.50 KB 0% 810 B
packages/workbox-webpack-plugin/build/generate-sw.js 8.04 KB 8.04 KB 0% 2.57 KB
packages/workbox-webpack-plugin/build/index.js 742 B 742 B 0% 470 B
packages/workbox-webpack-plugin/build/inject-manifest.js 10.30 KB 10.30 KB 0% 3.23 KB

Workbox Aggregate Size Plugin

9.97KB gzip'ed (66% of limit)
26.57KB uncompressed

@jeffposnick
Copy link
Contributor

There are also some changes that will need to made to https://developers.google.com/web/tools/workbox/guides/using-plugins#custom_plugins in a separate PR to reflect the new plugin parameters.

Yes, but I'm assuming that should wait until the next release, right?

Right; we don't have a great way of keeping track of that, so I tend to try to file a PR (or at least create a local commit with the change) against WebFundamentals at around the same time that the Workbox change goes in, and time the merge for when we cut the new Workbox release.

@jeffposnick
Copy link
Contributor

I'm curious to see whether the size differential goes down depending on the @babel/preset-env target, but I don't think the delta in sizes is blocking.

@philipwalton
Copy link
Member Author

I don't think preset-env is creating any extra size differential specific to these changes, but it does create a size differential in general (greater than these changes). For example, here's what the gzipped sizes look like comparing master, this PR, and then this PR without any babel transforms:

workbox-core size
master 2.84 kB
PR 2.9 kB
PR (w/o babel) 2.76 kB
workbox-strategies size
master 1.17 kB
PR 1.24 kB
PR (w/o babel) 1.12 kB

AFAICT, the main cause of the size increase is previously we could minify code like this:

cacheWrapper.match(s.e,r,s.s,s.t)

But now we're forced to minify it like this (from an actual diff):

cacheWrapper.match({cacheName:r.e,request:s,event:e,matchOptions:r.r,plugins:r.t});

And enough of these occurrences adds up I guess...

@jeffposnick
Copy link
Contributor

Ah, that makes sense regarding the parameter name mangling. Thanks for checking!

I'm cool with the extra bytes, especially since we have a plan for reducing bundle sizes once we hit v4 and can cut out some of the other transpilation overhead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants