add build version tracking with commit SHA, version number, and build timestamp to frontend
This commit is contained in:
@@ -4,21 +4,31 @@ import { useRegisterSW } from 'virtual:pwa-register/react';
|
||||
// Check for SW updates every hour and on tab focus/visibility change
|
||||
const UPDATE_INTERVAL_MS = 60 * 60 * 1000;
|
||||
|
||||
const buildLabel = `${__APP_VERSION__}-${__APP_COMMIT__}`;
|
||||
|
||||
export function UpdatePrompt() {
|
||||
const {
|
||||
needRefresh: [needRefresh],
|
||||
updateServiceWorker,
|
||||
} = useRegisterSW({
|
||||
onRegisteredSW(_swUrl, registration) {
|
||||
console.info('[App] version', {
|
||||
version: __APP_VERSION__,
|
||||
commit: __APP_COMMIT__,
|
||||
builtAt: __APP_BUILT_AT__,
|
||||
serviceWorker: registration ? 'registered' : 'unavailable',
|
||||
});
|
||||
|
||||
if (!registration) return;
|
||||
|
||||
const checkForUpdate = async () => {
|
||||
if (registration.installing || !navigator) return;
|
||||
if ('connection' in navigator && !navigator.onLine) return;
|
||||
try {
|
||||
console.debug('[PWA] checking for update', { version: buildLabel });
|
||||
await registration.update();
|
||||
} catch {
|
||||
// network error — ignore, will retry
|
||||
console.debug('[PWA] update check failed, will retry later', { version: buildLabel });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -34,7 +44,9 @@ export function UpdatePrompt() {
|
||||
|
||||
useEffect(() => {
|
||||
if (needRefresh) {
|
||||
console.log('[PWA] New version detected, auto-updating...');
|
||||
console.info('[PWA] new version detected, applying automatically', {
|
||||
currentVersion: buildLabel,
|
||||
});
|
||||
updateServiceWorker(true);
|
||||
}
|
||||
}, [needRefresh, updateServiceWorker]);
|
||||
|
||||
5
frontend/src/vite-env.d.ts
vendored
Normal file
5
frontend/src/vite-env.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
declare const __APP_VERSION__: string;
|
||||
declare const __APP_COMMIT__: string;
|
||||
declare const __APP_BUILT_AT__: string;
|
||||
Reference in New Issue
Block a user