Uh oh!
There was an error while loading. Please reload this page.
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#5491arackaf wants to merge 6 commits into
Conversation
Timer
commented
Oct 20, 2018
/cc @jeffposnick |
dominicarrojado
commented
Oct 20, 2018
How to do force the update without closing all tabs? How to implement skipWaiting with CRA? |
arackaf
commented
Oct 20, 2018
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. |
dominicarrojado
commented
Oct 20, 2018
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? |
arackaf
commented
Oct 20, 2018
To automatically have service workers skipWaiting, you’d need to override the sw configuration using something like customize-cra |
dominicarrojado
commented
Oct 20, 2018
@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.
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.
There are some issues with updating these links as these files (with the original links) are present in existing projects. More details here: #5536
arackaf
commented
Nov 7, 2018
@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? |
tyler-dunkel
commented
Nov 12, 2018
@arackaf regarding your statement about automatically |
arackaf
commented
Nov 13, 2018
“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 |
Timer
commented
Nov 13, 2018
Can you update the TS version too, please? |
arackaf
commented
Nov 13, 2018
@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? |
inssein
commented
Nov 21, 2018
@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
arackaf
commented
Nov 24, 2018
@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 |
arackaf
commented
Nov 24, 2018
@Timer sorry for the delay - how's that look? |
inssein
commented
Nov 24, 2018
You can't do that without ejecting though, right? |
arackaf
commented
Nov 24, 2018
@inssein - ah, sorry, no need to eject - just a lil tweak is all you need :) |
Uh oh!
There was an error while loading. Please reload this page.
samccone
commented
Jan 4, 2019
@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. |
danielkcz
commented
Feb 7, 2019
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. |
dominicarrojado
commented
Feb 7, 2019
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. |
danielkcz
commented
Mar 9, 2019
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. |
arackaf
commented
Apr 23, 2019
Any reason this was never merged? |
iansu
commented
Apr 24, 2019
@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. |
arackaf
commented
Apr 24, 2019
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 :) |
iansu
commented
Apr 24, 2019
That's actually one of the nicer responses to the stale bot that I've seen. 😀 |
FezVrasta
commented
Jun 6, 2019
Should you merge it? |
andriijas
commented
Jan 31, 2020
@arackaf thanks for your patience. could you rebase your branch on top of the latest changes? thanks |
arackaf
commented
Jan 31, 2020
Not really. It's been years since I even looked at this. I'd recommend just merging and pushing. |
andriijas
commented
Jan 31, 2020
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 |
arackaf
commented
Jan 31, 2020
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.