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

HTML Caching and SW Communication API Implementation. #1905

Merged
merged 101 commits into from
Oct 31, 2019

Conversation

revanth0212
Copy link
Contributor

@revanth0212 revanth0212 commented Oct 18, 2019

Description

HTML Caching and Service Worker Communication API Implementation. The service worker will be following the StaleWhileRevalidate strategy for all HTML files. It will return the readily available file from the cache and try to update the file in the background. If the file happens to be different from the one already in the cache, it will send a message to the UI about an update available and a button in the message to refresh the page.

Related Issue

Closes #1772 #1781

Verification Steps

  1. Build and start the server using yarn build && yarn stage:venia.
  2. Refresh the page once after it has loaded up. This will make sure that the Service Worker is installed successfully.
  3. Open venia-concept/dist/index.html and make a change like adding a new script tag
    <script>console.log('Hey this is a new HTML')</script>
  4. Now navigate to a different page like Category or Product by clicking on the appropriate links/pictures. Note: Do not refresh the page.
  5. Once you navigate to a new page, a toast should show up in the bottom letting you know that an update is available.

Screenshots / Screen Captures (if appropriate)

HTML Update Toast Demo

Checklist

  • No functional change. Make sure both yarn stage:venia and yarn watch:venia should work like previous.
  • Should be merged only after Service Worker HTML Handling #1874 is merged.

revanth0212 and others added 30 commits September 30, 2019 15:44
Co-Authored-By: Andy Terranova <13182778+supernova-at@users.noreply.github.com>
console.log('SW Registered');
})
.catch(() => {
window.console.warn('Failed to register SW.');
Copy link
Contributor

Choose a reason for hiding this comment

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

Why window here and not in the .then?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm yeah I thought this got dropped to just console.log and our minifier would drop console.logs (so this won't show up in production)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah console.* gets removed by webpack for production. But we need a warning for SW not registering. That is why I used window.console.*

Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment to that affect so we don't accidentally "fix" that in some later work.

Copy link
Contributor

@sirugh sirugh left a comment

Choose a reason for hiding this comment

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

Verification steps work! This looks good. I had a few small things I'd like to see but otherwise this is great. Fix them and I'll approve.

console.log('SW Registered');
})
.catch(() => {
window.console.warn('Failed to register SW.');
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment to that affect so we don't accidentally "fix" that in some later work.

@@ -0,0 +1,22 @@
import { handleMessageFromSW } from '@magento/venia-ui/lib/util/swUtils';
Copy link
Contributor

Choose a reason for hiding this comment

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

If moving this stuff to venia-concept is a "TODO" then open an issue for it :)

@revanth0212
Copy link
Contributor Author

Verification steps work! This looks good. I had a few small things I'd like to see but otherwise this is great. Fix them and I'll approve.

I have added the comment. Regarding moving files to venia-ui I am not sure if we need to do it or not. I feel we do but it is @zetlen who has to make the call.

@dpatil-magento dpatil-magento merged commit 1883d21 into develop Oct 31, 2019
@dpatil-magento dpatil-magento deleted the revanth/workboxWindowIntegration branch October 31, 2019 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:peregrine pkg:pwa-buildpack pkg:venia-concept pkg:venia-ui version: Minor This changeset includes functionality added in a backwards compatible manner.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature]: Implement API to listen to postMessages from Service Worker.
5 participants