Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/react-scripts/template/src/registerServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const isLocalhost = Boolean(
export default function register() {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
const publicUrl = new window.URL(process.env.PUBLIC_URL, window.location);
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
Expand Down Expand Up @@ -74,7 +74,7 @@ function registerValidSW(swUrl) {

function checkValidServiceWorker(swUrl) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl)
window.fetch(swUrl)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I don't think we want to do this. Pretty much all tutorials use fetch without qualifier and I don't want to confuse readers.

I'm fine with other changes but I'd rather keep this one as is. If somebody uses Standard they can feel free to change it by hand in their project.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a standard user also has the option of adding

"standard": { "globals": "fetch" }

to their package.json

.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
if (
Expand All @@ -100,8 +100,8 @@ function checkValidServiceWorker(swUrl) {
}

export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then(registration => {
if ('serviceWorker' in window.navigator) {
window.navigator.serviceWorker.ready.then(registration => {
registration.unregister();
});
}
Expand Down