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

feat: workbox-window method to trigger SW update check #2136

Merged
merged 4 commits into from
Aug 1, 2019

Conversation

jaulz
Copy link
Contributor

@jaulz jaulz commented Jul 20, 2019

R: @jeffposnick @philipwalton

Fixes #2130

This PR introduces an update method on the Workbox instance in order to check for updates after the page has loaded. This is useful for long running applications that are seldom closed (e.g. mail applications) and where you need to check for updates on regular time interval.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@jaulz
Copy link
Contributor Author

jaulz commented Jul 20, 2019

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@coveralls
Copy link

coveralls commented Jul 20, 2019

Coverage Status

Coverage increased (+0.08%) to 78.731% when pulling 364c488 on jaulz:feat/window-update into b0825d7 on GoogleChrome:master.

}

// Reset the registration time and update count so it's not treated as
// external in the `this._onUpdateFound` heuristic.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure resetting these here is what we want to do. Based on how I describe the intention of the "external" events in the workbox-window guide, an update found via calling update() is (for all intents and purposes) the same as an update found via the app being updated in a new tab.

Do you disagree? Based on what you said in this comment I thought you wanted to treat them the same way: #2130 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it now but I don't understand why an update via update() is the same as an update via a new tab? Isn't the update eventually the same as a register() which is called after the page has been loaded?

Copy link
Member

Choose a reason for hiding this comment

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

Isn't the update eventually the same as a register() which is called after the page has been loaded?

Not quite. The difference is register() is always called first, and after the register() call you either have an update or you don't. But when you have an update from the register() call (in the same tab), it's always for a SW that is older (or the same age) as the code running on the window.

But if an update is found when calling update() (or .register() in another tab in the future), it means the updated SW is newer than the code running on the page, which means there could potentially be conflicts, depending on how old the code running on the page is.

@philipwalton
Copy link
Member

Thanks, this looks good now. Do you want to try adding a test to https://github.com/GoogleChrome/workbox/blob/ba31cb87236ac4d3b1cd9c1b6580d518a6d47b73/test/workbox-window/window/test-Workbox.mjs?

You can debug the window tests by running gulp test-server in your terminal, and then visiting http://localhost:3004/test/workbox-window/window/ in your browser to see the results.

If you're not sure how to do that (or have problems getting the tests to run), I can merge your changes into another branch and add the tests myself when I get a chance.

@jaulz
Copy link
Contributor Author

jaulz commented Jul 25, 2019

Okay, I added some tests... though, I couldn't find out how to actually replicate an update (i.e. a file change). Any idea or do you think these tests are enough?

@philipwalton
Copy link
Member

Thanks! (Sorry for the relayed reply)

@philipwalton philipwalton merged commit 9282ab0 into GoogleChrome:master Aug 1, 2019
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.

workbox-window method to trigger SW update check
4 participants