Skip to content

"Service worker response error" after upgrade to CRA3 #7537

Closed
@danielkcz

Description

@danielkcz

We have the CRA3 app (react-scripts 3.1.1, not ejected) that is just fine across multiple platforms and devices. But one specific case is Android native app which runs the app in Google WebView (wrong business decision, don't ask).

Sadly, the problem is rather random and happens on app reload where service worker responds with code 500 and fails to provide one or more of the chunks. There are no further details for the error. Also, no app updates happen during that time. I can even disconnect from the network and it still happens.

image

With CRA2 it works just fine. Even if I simply downgrade to latest react-scripts@2, make a build, the problem never occurs.

Looking through changelog only possible suspect seems upgrade of workbox to V4.

ping @r0ughnex as the author of #6725 and possibly @rovansteen who was trying help me in #6243 and @jeffposnick as a Google guy :)


In case it's relevant, we have pretty much the same service-worker.js that is shipped with CRA except some extra hooks to detect updates and such. Then we have this ugly script that's shipped inside the build and injected into a workbox setup with customize-cra. It's used to postMessage from the app when a user clicks on "update now" button.

self.addEventListener('message', event => {
  if (event.data == 'apply-update') {
    self.skipWaiting().then(() => {
      self.clients.claim().then(() => {
        self.clients.matchAll().then(clients => {
          clients.forEach(client => client.postMessage('update-applied'))
        })
      })
    })
  }
})

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions