Skip to content

Commit

Permalink
Merge pull request #194 from xwp/fix/importscripts-after-install
Browse files Browse the repository at this point in the history
Guard against causing Workbox to call importScripts() after SW installation
  • Loading branch information
westonruter authored Jul 14, 2019
2 parents 7cf111f + e850561 commit 16397ba
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions wp-includes/js/service-worker-navigation-routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ ERROR_OFFLINE_BODY_FRAGMENT_URL, STREAM_HEADER_FRAGMENT_QUERY_VAR, NAVIGATION_BL
const errorMessages = ERROR_MESSAGES;
const navigationRouteEntry = NAVIGATION_ROUTE_ENTRY;

/*
* Define strategy up front so that Workbox modules will import at install time.
* If this is not done, then an error will happen like:
* > Unable to import module 'workbox-expiration'
* Along with an exception:
* > workbox-sw.js:1 Uncaught (in promise) DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope'
*/
const navigationCacheStrategy = new wp.serviceWorker.strategies[ CACHING_STRATEGY ]( CACHING_STRATEGY_ARGS );

/**
* Handle navigation request.
*
Expand Down Expand Up @@ -134,8 +143,6 @@ ERROR_OFFLINE_BODY_FRAGMENT_URL, STREAM_HEADER_FRAGMENT_QUERY_VAR, NAVIGATION_BL
}
}

const navigationCacheStrategy = new wp.serviceWorker.strategies[ CACHING_STRATEGY ]( CACHING_STRATEGY_ARGS );

if ( canStreamResponse() ) {
const streamHeaderFragmentURL = STREAM_HEADER_FRAGMENT_URL;
const precacheStrategy = new wp.serviceWorker.strategies.cacheFirst({
Expand Down

0 comments on commit 16397ba

Please # to comment.