Implement PWA auto-update strategy with silent cache cleanup and toast notification#4
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Copilot
AI
changed the title
[WIP] Implement cache strategy and automatic update for PWA
Implement PWA auto-update strategy with silent cache cleanup and toast notification
May 16, 2026
will-aam
approved these changes
May 16, 2026
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the PWA cache management strategy from
docs/PWA_CACHE_STRATEGY.md: the app now silently applies Service Worker updates without user intervention, clears stale caches automatically, and briefly notifies the user before reloading — all without touchinglocalStorage(preserving theme preference).Changes
next.config.mjs— Enabledregister: true,skipWaiting: true, andcleanupOutdatedCaches: trueon the@ducanh2912/next-pwaconfig.cleanupOutdatedCachesonly purges Cache API storage, leavinglocalStorageintact.components/pwa-updater.tsx— New"use client"component that binds tonavigator.serviceWorker'scontrollerchangeevent, fires asonnertoast, then reloads after 1.5s:app/layout.tsx— Mounts<PWAUpdater />insideThemeProviderin the root layout so the listener is active on every page. Also adds?v=2cache-busting to manifest and icon links to force re-fetch of PWA assets on deploy.Original prompt
O usuário quer implementar a estratégia de cache e atualização automática de PWA documentada no arquivo
PWA_CACHE_STRATEGY.md. O objetivo é garantir que o app se atualize silenciosamente e limpe o cache antigo do Service Worker, mas sem perder as preferências do usuário (como o tema escuro/claro salvo em localStorage/cookies), além de exibir um aviso visual (Toast) quando uma atualização estiver sendo aplicada.Por favor, faça o seguinte no repositório
will-aam/totten:next.config.mjsounext.config.ts/next.config.js. Garanta que as opçõesregister: true,skipWaiting: trueecleanupOutdatedCaches: trueestejam habilitadas. OcleanupOutdatedCacheslimpa apenas o armazenamento de Cache API do Service Worker, não afetando olocalStorage, o que atende perfeitamente ao requisito de não perder o tema.components/pwa-updater.tsxou similar). Ele deve rodar no cliente ("use client";), escutar o eventocontrollerchangedonavigator.serviceWorker, exibir um toast informando sobre a atualização usando a biblioteca de toasts já existente no projeto (ex:sonnerque faz parte da stack shadcn-ui no projeto) e dar owindow.location.reload().PWAUpdaterno layout principal (app/layout.tsx), para que o listener funcione em todas as páginas.?v=2ou similar) nos links de manifesto e ícones se existirem no projeto, para forçar o cache busting.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: ```
"use client";
import { useState, useEffect, useRef, useCallback } from "react";
import useSWR from "swr";
import useSWRInfinite from "swr/infinite";
import Link from "next/link";
import { useSession } from "next-auth/react";
import { AdminHeader } from "@/components/admin-header";
import { PendingCheckInsCard } from "@/components/admin/pending-checkins-card";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { Skeleton } from "@/components/ui/skeleton";
import {
CalendarCheck,
Group,
AlertTriangle,
Clock,
ChevronUp,
RefreshCw,
User,
} from "@boxicons/react";
import type { BoxIconProps } from "@boxicons/react";
import { cn } from "@/lib/utils";
const fetcher = (url: string) => fetch(url).then((r) => r.json());
type CheckIn = {
id: string;
client_id: string;
client_name: string;
date_time: string;
professional_name?: string | null;
};
function KpiCard({
title,
value,
description,
icon: Icon,
className,
}: {
title: string;
value: string | number;
description: string;
icon: React.ForwardRefExoticComponent<
BoxIconProps & React.RefAttributes
function CheckInListItem({ checkIn }: { checkIn: CheckIn }) {
const date = new Date(checkIn.date_time);
const formattedDate = date.toLocaleDateString("pt-BR", {
day: "2-digit",
month: "short",
});
const formattedTime = date.toLocaleTimeString("pt-BR", {
hour: "2-digit",
minute: "2-digit",
});
const initial = checkIn.client_name
? checkIn.client_name.charAt(0).toUpperCase()
: "?";
return (
<Link
href={checkIn.client_id ?
/admin/clients/${checkIn.client_id}: "#"}className="flex items-center gap-3 md:gap-4 cursor-pointer hover:opacity-80 transition-opacity"
>
{initial}
{checkIn.clien...
This pull request was created from Copilot chat.