Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError 'onSuccess' of undefined #5299

Closed
peterbe opened this issue Oct 5, 2018 · 3 comments
Closed

TypeError 'onSuccess' of undefined #5299

peterbe opened this issue Oct 5, 2018 · 3 comments

Comments

@peterbe
Copy link

peterbe commented Oct 5, 2018

Is this a bug report?

Yes.

Did you try recovering your dependencies?

Not applicable.

Which terms did you search for in User Guide?

Making a Progressive Web App

Environment


  System:
    OS: macOS High Sierra 10.13.6
    CPU: x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
  Binaries:
    Node: 10.11.0 - /usr/local/bin/node
    Yarn: 1.10.1 - /usr/local/bin/yarn
    npm: 6.4.1 - /usr/local/bin/npm
  Browsers:
    Chrome: 69.0.3497.100
    Safari: 12.0
  npmPackages:
    react: 16.5.2 => 16.5.2 
    react-dom: 16.5.2 => 16.5.2 
    react-scripts: 2.0.4 => 2.0.4 
  npmGlobalPackages:
    create-react-app: Not Found

The ^ output doesn't say but I'm on react-scripts 2.0.4 as you can see here:
https://github.com/peterbe/workon/blob/223dac8c62dda95c313bc57f6a9adc5362290a46/package.json#L29

Steps to Reproduce

  1. Use Firefox Nightly (because that's the only way you can remove all previous service workers)
  2. Visit https://workon.app/
  3. First time it registers the service worker only you get this error:

Expected Behavior

Not get an error.

Actual Behavior

screen shot 2018-10-04 at 8 58 32 pm

Reproducible Demo

Check out https://github.com/peterbe/workon/tree/223dac8c62dda95c313bc57f6a9adc5362290a46 and yarn install, yarn run build and serve -s build.

Or, if you have no previous service worker before open: https://workon.app

@peterbe
Copy link
Author

peterbe commented Oct 5, 2018

Actually, I'm not sure I know how to reproduce this. Anyway...

The bug is that calling serviceWorker.register(); inside your src/index.js will eventually lead to the lines:

              // Execute callback
              if (config.onUpdate) {
                config.onUpdate(registration);
              }

But if config is undefined you get a TypeError:

screen shot 2018-10-04 at 9 04 32 pm

@peterbe
Copy link
Author

peterbe commented Oct 5, 2018

Solution is to either do serviceWorker.register({}); or changing the unsafe line to:

              // Execute callback
              if (config && config.onUpdate) {
                config.onUpdate(registration);
              }

@peterbe
Copy link
Author

peterbe commented Oct 5, 2018

By the way, I applied the fix I mentioned in the PR by making this change so now it's no longer reproducible by visiting workon.app.

Timer pushed a commit that referenced this issue Oct 5, 2018
…5301)

* avoid TypeError on when registering service workers without config

Fixes #5299

* same before config.onUpdate
zmitry pushed a commit to zmitry/create-react-app that referenced this issue Oct 29, 2018
…acebook#5301)

* avoid TypeError on when registering service workers without config

Fixes facebook#5299

* same before config.onUpdate
@lock lock bot locked and limited conversation to collaborators Jan 10, 2019
Pong420 pushed a commit to Pong420/create-react-app that referenced this issue Feb 24, 2019
…acebook#5301)

* avoid TypeError on when registering service workers without config

Fixes facebook#5299

* same before config.onUpdate
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant