title: Create-react-app reload on service worker update
body: <p>I want to modify <code>create-react-app</code> service worker <a href="https://github.com/facebook/create-react-app/blob/d57fd37d2d9df1d40aed061e4446831be70446ca/packages/react-scripts/template/src/serviceWorker.js" rel="nofollow noreferrer">file</a> and implement popup message which will ask user to update app if newer service worker is ready to be activated. I'm almost done with the solution but have one pitfall. I want to reload the app when user confirms service worker update popup, so I've added some coded to the end of <code>register</code> function, see below:</p>
  
  <pre><code>export default function register(config) {
    if (process.env.NODE_ENV === "production" &amp;&amp; "serviceWorker" in navigator) {
      // The URL constructor is available in all browsers that support SW.
      const publicUrl = new 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
        // serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
        return
      }
  
      window.addEventListener("load", () =&gt; {
        const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`
  
        if (isLocalhost) {
          // This is running on localhost. Lets check if a service worker still exists or not.
          checkValidServiceWorker(swUrl, config)
  
          // Add some additional logging to localhost, pointing developers to the
          // service worker/PWA documentation.
          navigator.serviceWorker.ready.then(() =&gt; {
            console.log(
              "This web app is being served cache-first by a service " +
                "worker."
            )
          })
        } else {
          // Is not local host. Just register service worker
          registerValidSW(swUrl, config)
        }
  
        let preventDevToolsReloadLoop
        navigator.serviceWorker.addEventListener("controllerchange", function() {
          // ensure refresh is called only once
          if (preventDevToolsReloadLoop) {
            return
          }
  
          preventDevToolsReloadLoop = true
          console.log("reload")
          window.location.reload(true)
        })
      })
    }
  }
  </code></pre>
  
  <p>But the problem is that it reloads the app also on first visit, when there doesn't exist any service worker yet. How can I solve it?</p>