Skip to content

Commit

Permalink
Mirror changes in JS version of SW
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Oct 24, 2018
1 parent 9e8e995 commit 9782cb9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/react-scripts/template/src/serviceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ function registerValidSW(swUrl, config) {
.then(registration => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
return;
}
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
Expand Down Expand Up @@ -100,9 +103,10 @@ function checkValidServiceWorker(swUrl, config) {
fetch(swUrl)
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type');
if (
response.status === 404 ||
response.headers.get('content-type').indexOf('javascript') === -1
(contentType != null && contentType.indexOf('javascript') === -1)
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
Expand Down

0 comments on commit 9782cb9

Please sign in to comment.