Open SebasG22 opened 4 years ago
@SebasG22 Hey, Why you didn't use notification API instead ?
@SebasG22 Hey, Why you didn't use notification API instead ?
Also there is no element in index.html with class snackbarPWA
@jtiala This code doesn't seem to work. One has to reload the page to get the new service worker running.
Hey @hunarjain007,
.snackbarPWA
should be #snackbarPWA
.service-worker
that is generated automatically by CRA. So the missing piece is to add the message listener
in the worker and will work.
For the limitation, I propose some solutions like workbox
.@SebasG22 The snackbar appears only when user refreshes the page... so even if there is listener attached on the click of snackbar, but still snackbar will not appear.
This PR includes small changes in the way that
react-app
handle the SW.snackbar
element that hasvisibility: none
until detecting a newserviceWorker
is detected Note: The classshow is added to set the
visibility: visible``)_.serviceWorker.ts
I added an extra param to theonUpdate
callback, to be able to send a message to theservice worker
.index.tsx
, I added theonUpdate
callback to handle the notification and when you clicked to send a message to the worker to perform the update action.Just have one missing step, configure the
service-worker.js
generated by react-app. I made a little research and found that you need toeject
the problem to handle this limitation. Limitations of default PWAs in CRAI don't like the idea of
eject
the project for many reasons ( You need to tackle all the issues regarding customconfiguration
).I've been working with PWA for almost 2 years, I highly recommend that instead of using the CRA Package for PWA's, use Workbox the facto to manage service workers for all kind of javascript apps. They offer a lot of great customization without ejecting the project and the only change that is needed is included as a dependency and running the command on the
build
pipeline.By the way, the missing step is: Listen to the message and
![image](https://user-images.githubusercontent.com/17608169/66709152-290f0800-ed23-11e9-8ddd-4d40b435eeb0.png)
skipWaiting
to update all the clients(tabs) open :