add build version tracking with commit SHA, version number, and build timestamp to frontend
Some checks failed
Build and Push Docker Images / build-backend (push) Has been cancelled
Build and Push Docker Images / build-frontend (push) Has been cancelled

This commit is contained in:
Egor Pozharov
2026-05-04 16:08:37 +06:00
parent a3929bec8d
commit f9c54b5172
5 changed files with 39 additions and 3 deletions

View File

@@ -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
View 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;