-
-
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
Make onUpdate callback fire when a new service worker is intalled and waiting #5491
Make onUpdate callback fire when a new service worker is intalled and waiting #5491
Conversation
…talled and waiting
/cc @jeffposnick |
How to do force the update without closing all tabs? How to implement skipWaiting with CRA? |
That has to be done client side. skipWaiting would be called in the callback you provide for onUpdate, which would then post a message that client side code would have to receive, and then manually refresh. |
But the event listener for the message to skipWaiting should be on the service worker file which is only available after build. Is there a way without touching the build files? |
To automatically have service workers skipWaiting, you’d need to override the sw configuration using something like customize-cra |
@arackaf Thank you, that's exactly what I need. |
I chatted with @arackaf about this logic and it looks 👍 Thanks for putting the PR together! |
// content until all client tabs are closed. | ||
console.log( | ||
'New content is available and will be used when all ' + | ||
'tabs for this page are closed. See http://bit.ly/CRA-PWA.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat PR!
This bit.ly
link needs to be pointed to https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
now. I created http://bit.ly/CRA2-PWA
but not sure if @gaearon wants to do it from his own account or something similar :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some issues with updating these links as these files (with the original links) are present in existing projects. More details here: #5536
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I see. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
@jeffposnick - just tweaked things to pass the updated sw to the onUpdate callback, so client code can postMessage to it. Anything blocking this from getting merged? |
@arackaf regarding your statement about automatically |
“closing and reopening the tab” Yeah, by default that’s what the user has to do to get the new sw. Once this pr is merged you’ll be able to do something like this https://twitter.com/adamrackis/status/1060036913921449984?s=21 |
Can you update the TS version too, please? |
@Timer sorry? There's a TS version of this same file? Where? |
@arackaf Thanks for the quick answer! one other question if you dont mind: what does this mean in the context of installed apps on mobile homescreens? Also, regarding the tweet you shared, I see that part of that solution involves updating the service-worker file itself to add the message event handler. So this would require using something to customize C-R-A's generated service-worker file? |
@arackaf this PR only makes sense once you can customize you service worker to skip waiting. I saw your tweet, but don't understand where the code in the third screenshot is placed. |
I am trying to describe 2 scenarios which can be used in PWA app to show message, reload the app UI
Requirements:
onUpdateAvailable/onUpdate callback onUpdateActivated/onActivated callback
OR
|
…ice-worker-update-tweak
@inssein screenshot #3 is code that you manually wire into the service worker via importScripts, via workbox configuration https://github.com/arackaf/booklist/blob/master/react-redux/webpack.config.js#L116 |
@Timer sorry for the delay - how's that look? |
You can't do that without ejecting though, right? |
@inssein - ah, sorry, no need to eject - just a lil tweak is all you need :) |
packages/react-scripts/template-typescript/src/serviceWorker.ts
Outdated
Show resolved
Hide resolved
@gaearon Hey Dan, anything I can do to help move this along? This is a major win to those of us out there that are using CRA + SW integration. Thanks so much for your time and please do let me know what I can do to help. |
This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
Well, this is getting kinda sad. This thing is working quite nicely, I have it in a production of two apps. Not sure why it's being held back so badly. |
Yeah, same here as well. I also used this for my apps. |
This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
Here we go again :) Stale bot, go away! |
This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
Any reason this was never merged? |
@arackaf No, I don't think there was a reason. It just fell through the cracks while we were working on 3.0. We'll take a closer look at it and see if we can get it into an upcoming release. |
Sweet, thanks! Sorry if my comment came off as snarky - I just needed something so the bot wouldn't close, and that's what my brain tossed out :) |
That's actually one of the nicer responses to the stale bot that I've seen. 😀 |
Should you merge it? |
@arackaf thanks for your patience. could you rebase your branch on top of the latest changes? thanks |
Not really. It's been years since I even looked at this. I'd recommend just merging and pushing. |
That was my idea. I had some time over today and have been working through long running PRs. Given this was already approved I wanted to get it in however there are conflicting files. I understand your frustration. Just let us know if you want to give it one more time or if we should close this or if there is someone else who can continue. Sorry for any inconvinience |
Yeah it's been years since I even looked at this project. I wouldn't really feel comfortable trying to resolve conflicts, nor am I in a position to test the resuls easily. |
Simple change to have the onUpdate callback fire when a newly installed service worker is waiting. This ensures the notification will not just come the first time the sw is updated, but rather each refresh until it takes over.
The modified code was run in my local project, and the onUpdate did continue to show on each refresh until all tabs were closed, and the new sw took over.