Skip to content

Commit

Permalink
fix(gatsby,gatsby-plugin-offline): register offline plugin when not o…
Browse files Browse the repository at this point in the history
…n preview (#30984)
  • Loading branch information
wardpeet authored Apr 22, 2021
1 parent 4f2b721 commit 17f028d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/gatsby-plugin-offline/src/gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.registerServiceWorker = () => true
exports.registerServiceWorker = () => process.env.GATSBY_IS_PREVIEW !== `true`

// only cache relevant resources for this page
const whiteListLinkRels = /^(stylesheet|preload)$/
Expand All @@ -8,6 +8,10 @@ exports.onServiceWorkerActive = ({
getResourceURLsForPathname,
serviceWorker,
}) => {
if (process.env.GATSBY_IS_PREVIEW === `true`) {
return
}

// if the SW has just updated then clear the path dependencies and don't cache
// stuff, since we're on the old revision until we navigate to another page
if (window.___swUpdated) {
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/cache-dir/production-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ navigationInit()
apiRunnerAsync(`onClientEntry`).then(() => {
// Let plugins register a service worker. The plugin just needs
// to return true.
if (apiRunner(`registerServiceWorker`).length > 0) {
if (apiRunner(`registerServiceWorker`).filter(Boolean).length > 0) {
require(`./register-service-worker`)
}

Expand Down

0 comments on commit 17f028d

Please sign in to comment.