-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Extract service worker registration code #2638
Comments
cc @viankakrisna @ro-savage would either of you be interested in tackling this? |
Played around with it on https://github.com/viankakrisna/create-react-app/blob/ServiceWorkerUtils/packages/react-dev-utils/ServiceWorkerUtils.js Found a few questions:
|
If you don't mind, a separate PR that moves everything to |
That's a good point. I haven't thought about that. I'm not sure.
Kind of.. But the boundary is a bit blurred here. I was hoping to cheat a little bit. |
how about option 1b? |
That's the part I'm not very happy about. If we can find any other useful stuff to go there though, maybe it's okay. |
@viankakrisna option 1d seems to be easiest, if writing in es6 is causing issues. Should be easy enough to do, happy to re-write it if you need. |
@ro-savage In the long run I think setting up build tool for react-dev-utils or registerServiceWorker as a separate top level package is better. The browser that supports service-worker should support parts of es6 too right? we can use babel-preset-env for that. @gaearon Another option is to set registerServiceWorker as a global function, so we don't need to import it from src. No react-scripts to react-dev-utils renaming on eject. |
IMHO library should be imported inside application import registerServiceWorker from './registerServiceWorker';
export default class App {
constructor(props) {
registerServiceWorker({
onUpdate: this.handleServiceWorkerUpdate
})
}
handleServiceWorkerUpdate(registration) {
if (window.confirm('New update has been installed, click to restart')) {
window.location.reload()
}
}
} |
I have side question about UX of
|
@stereobooster I think update notification implementation should be up to developer. For example I'm showing special icon when update is detected and user may click on it to reload page into new state. This problem should be really separated into two pull requests:
More info in here: #3375 |
This feature is still in flux, by the time TMA is ready to launch this feature will likely have a new implementation. Re: facebook/create-react-app#2638 facebook/create-react-app#2398
This feature is still in flux, by the time TMA is ready to launch this feature will likely have a new implementation. Re: facebook/create-react-app#2638 facebook/create-react-app#2398
Meh. I’m fairly happy with what we have now and don’t think extracting it is all that useful. People who want service workers probably want more control anyway. |
Judging by #2551 and #2426 we're going to make more changes to SW registration code. I think it means we should move a bulk of the implementation into the library but expose the necessary hooks for 80% use cases (e.g. for showing a custom toast).
How this could work:
On ejecting, we'll replace
react-scripts
reference withreact-dev-utils
. The file will exist as an extra entry point in both packages, so it will work both before and after ejecting.Note: this also means
react-scripts
will move todependencies
fromdevDependencies
. This actually seems fine and reasonable to me. The distinction doesn't really make sense anyway.The exact naming is up for debate.
The text was updated successfully, but these errors were encountered: