Skip to content

Commit 9782cb9

Browse files
committed
Mirror changes in JS version of SW
1 parent 9e8e995 commit 9782cb9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/react-scripts/template/src/serviceWorker.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ function registerValidSW(swUrl, config) {
6060
.then(registration => {
6161
registration.onupdatefound = () => {
6262
const installingWorker = registration.installing;
63+
if (installingWorker == null) {
64+
return;
65+
}
6366
installingWorker.onstatechange = () => {
6467
if (installingWorker.state === 'installed') {
6568
if (navigator.serviceWorker.controller) {
@@ -100,9 +103,10 @@ function checkValidServiceWorker(swUrl, config) {
100103
fetch(swUrl)
101104
.then(response => {
102105
// Ensure service worker exists, and that we really are getting a JS file.
106+
const contentType = response.headers.get('content-type');
103107
if (
104108
response.status === 404 ||
105-
response.headers.get('content-type').indexOf('javascript') === -1
109+
(contentType != null && contentType.indexOf('javascript') === -1)
106110
) {
107111
// No service worker found. Probably a different app. Reload the page.
108112
navigator.serviceWorker.ready.then(registration => {

0 commit comments

Comments
 (0)