Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support offline mode after the first Playground page load (#1643)
A set of bugfixes and enhancements for [PR 1535 – Cache Playground assets to enable offline support](#1535): ### Offline mode after a single page load **Without this PR:** When the service worker is first registered, it does not yet handle the network requests triggered by the page that registered it. Files fetched on the initial Playground load, like `wordpress-static.zip`, are not cached. This means the offline mode won't work yet. You need to do a full page reload, wait for another round of `fetch()`-es, and only then you get cached assets and a functional offline mode. **With this PR:** Service Worker calls `self.clients.claim()` to start controlling the Playground page when the service worker is initially registered. Static assets are cached and offline mode works after the very first page load. ### Backfill static assets before the first paint * If `wordpress-static.zip` is cached, it will be extracted during Playground boot. * If it's not cached, we'll boot and render Playground first, and only then start downloading and extracting that file. ### Other smaller changes * Simplified OfflineModeCache, used class methods (`function myFn(){}` instead of instance methods (`myFn = () => {}`) cc @bgrgicak --------- Co-authored-by: Bero <berislav.grgicak@gmail.com>
- Loading branch information