Skip to content

PWA / Service worker breaking production deployments #2440

Closed
@ro-savage

Description

@ro-savage
Contributor

EDIT: Issue appears to be with Firebase only

Service workers aren't refreshing index.html and therefore new deploys are showing old bundles.

This means production websites or really all deployed sites that use a single url/domain can not be updated.

PR #2441 - Is a hotfix (if needed) that just removes the service worker and updates docs to say they have been disabled temporarily.

@gaearon @Timer @jeffposnick @addyosmani

Steps to reproduce

  • create-react-app sw-test
  • cd sw-test
  • npm install
  • npm run build
  • cd build

Deploy with firebase

  • firebase deploy
  • Visit site https://[project].firebaseapp.com. Confirm working.
  • Change app.js
  • npm run build
  • cd build
  • deploy firebase

Check website

  • Visit site again and no changes shown. DevTools shows SW is providing index.html and old bundles.
  • Force refresh a few times. No difference.
  • Delete service worker.
  • Refresh.
  • See correctly updated site.

Can someone else confirm this is affecting them?

I am hoping I am doing something wrong and this isn't affecting every production deploy.

Activity

ro-savage

ro-savage commented on Jun 1, 2017

@ro-savage
ContributorAuthor

Additionally, you can not remove the service worker because if you try to unregister in a new deploy, the user will never see the updated bundle.

gaearon

gaearon commented on Jun 1, 2017

@gaearon
Contributor
changed the title [-]CRITICAL: PWA / Service worker not refreshing on deployment in production[/-] [+]CRITICAL: PWA / Service worker breaking production deployments[/+] on Jun 1, 2017
bunshar

bunshar commented on Jun 1, 2017

@bunshar
Contributor

Looks like something to do with "now". Works for me - Checked with "surge" and localhost

gaearon

gaearon commented on Jun 1, 2017

@gaearon
Contributor
ro-savage

ro-savage commented on Jun 1, 2017

@ro-savage
ContributorAuthor

Thank you @bunshar !

I tried surge on a new project built from scratch. And it working as expected.

Deployed same app on now and its working as expected.

No idea what happened or what I did different.

Happy to close this and assume I managed to screw something up multiple times and over-react.

I will keep an eye on my projects and see if I can narrow down what happened.

changed the title [-]CRITICAL: PWA / Service worker breaking production deployments[/-] [+]PWA / Service worker breaking production deployments[/+] on Jun 1, 2017
ro-savage

ro-savage commented on Jun 1, 2017

@ro-savage
ContributorAuthor

Still running into issues on firebase.

Deploying same newly create app to now, surge and firebase.

now and surge are updating. firebase is not. (newly created project: https://cra-sw.firebaseapp.com/)

Will see if its working tomorrow and will contact firebase and see what they say.

ro-savage

ro-savage commented on Jun 1, 2017

@ro-savage
ContributorAuthor

Just to prove I am not crazy and this is a thing on firebase.

Deploying changes with serve, now, surge and firebase.
Approximately 3 minutes
https://www.youtube.com/watch?v=oYy-WqkgS1Q

reopened this on Jun 1, 2017
gaearon

gaearon commented on Jun 1, 2017

@gaearon
Contributor

Let’s keep it open and wait for @jeffposnick to help with diagnosing this.

11 remaining items

gaearon

gaearon commented on Jan 8, 2018

@gaearon
Contributor

Closing in favor of #2398.

lusan

lusan commented on Feb 1, 2018

@lusan

Hi everyone, sorry for asking a similar question in a closed issue, thought it is related to it and the solution might be simple.

I am trying to set cache header for sw with nginx, in the configuration like it has been done in firebase, I tried

location /service-worker.js {
    add_header Cache-Control "no-cache";
    proxy_cache_bypass $http_pragma;
    proxy_cache_revalidate on;
    expires off;
    access_log off;
}

However when I load my page, sw registration fails with the message.

A bad HTTP response code (404) was received when fetching the script. registerServiceWorker.js:71 Error during service worker registration: TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script.

@gaearon @Timer @jeffposnick @addyosmani @mbleigh

Can someone please help me with this?

added a commit that references this issue on Feb 13, 2018
j-lee8

j-lee8 commented on Jan 13, 2019

@j-lee8

Is anybody still experiencing this issue? I've just created an app via create-react-app and deployed it to Firebase but when I check the Network and Application tabs in dev tools the service worker isn't there? When I do a local serve -s build it runs perfectly, but it doesn't appear to be loaded through Firebase.

Doing a Lighthouse audit it says there is no service worker on the page, yet inside the build dir the service-worker.js is there and it's also inside the asset-manifest.json.

Thanks all!

locked and limited conversation to collaborators on Jan 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mbleigh@addyosmani@gaearon@jeffposnick@antmarot

        Issue actions

          PWA / Service worker breaking production deployments · Issue #2440 · facebook/create-react-app