revalidate loaders on message reception
This commit is contained in:
@ -117,7 +117,7 @@ export function fetchLoaderData(event: FetchEvent): Promise<Response> {
|
||||
// and if we had returned a cached response
|
||||
// tell the UI to fetch the latest data
|
||||
console.debug("Revalidate loader data", path);
|
||||
const channel = new BroadcastChannel("sw-messages");
|
||||
const channel = new BroadcastChannel("revalidate");
|
||||
channel.postMessage("revalidateLoaderData");
|
||||
lastTimeRevalidated[path] = Date.now();
|
||||
}
|
||||
@ -193,7 +193,7 @@ export async function purgeMutatedLoaders(event: FetchEvent) {
|
||||
const cachedPathname = new URL(loader.url).pathname;
|
||||
const shouldPurge = cachedPathname.startsWith(rootPathname);
|
||||
|
||||
if (url.pathname === "/settings/phone") {
|
||||
if (["/dev/null", "/settings/phone"].includes(url.pathname)) {
|
||||
// changes phone number or twilio account credentials
|
||||
// so purge messages and phone calls from cache
|
||||
return (
|
||||
|
@ -15,12 +15,17 @@ export default async function handlePush(event: PushEvent) {
|
||||
const payload: NotificationPayload = event.data!.json();
|
||||
const options = Object.assign({}, defaultOptions, payload);
|
||||
|
||||
const revalidateChannel = new BroadcastChannel("revalidate");
|
||||
// should revalidate just "/messages" and `/messages/${encodeURIComponent(payload.data.recipient)}`
|
||||
revalidateChannel.postMessage("revalidateLoaderData");
|
||||
revalidateChannel.close();
|
||||
|
||||
const clients = await self.clients.matchAll({ type: "window" });
|
||||
const hasOpenTab = clients.some((client) => client.focused === true);
|
||||
if (hasOpenTab) {
|
||||
const channel = new BroadcastChannel("notifications");
|
||||
channel.postMessage(JSON.stringify(payload));
|
||||
channel.close();
|
||||
const notifyChannel = new BroadcastChannel("notifications");
|
||||
notifyChannel.postMessage(JSON.stringify(payload));
|
||||
notifyChannel.close();
|
||||
} else {
|
||||
await self.registration.showNotification(payload.title, options);
|
||||
await addBadge(1);
|
||||
|
Reference in New Issue
Block a user