Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !3375

Provide callbacks in registerServiceWorker (1.x)

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/piotr-cz/patch-2 into master Oct 31, 2017
  • Overview 7
  • Commits 3
  • Pipelines 0
  • Changes 1

Created by: piotr-cz

Adding two callbacks in registerServiceWorker file:

  • onUpdate - executed after console logs New content is available; please refresh.
  • onSuccess - executed after console logs Content is cached for offline use.

This is a more lightweight change, compared to other related PR: https://github.com/facebookincubator/create-react-app/pull/2426 as in my opinion problem should be separated into two parts:

  • Providing callbacks in registerServiceWorker.js file
  • Adding an callback notification (Toast) that may be customized by developer

How callbacks are provided or named is up to discussion, the point is to provide minimal working technique to detect update.

When this or similar PR is landed on master branch we can discuss how to notify user about the update.

To use it inside application to show notification (toast/ icon etc) register service worker inside App.js file:

import registerServiceWorker from './registerServiceWorker.js'

export default class App {
  constructor(props) {
    // Register service worker and add onUpdate callback
    registerServiceWorker({
      onUpdate: this.handleServiceWorkerUpdate
    })
  }

  // Simplest notification implementation example.
  handleServiceWorkerUpdate(registration) {
    if (window.confirm('New update has been installed, click to restart')) {
      window.location.reload()
    }
  }
}
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/piotr-cz/patch-2