fix: improve service worker offline flow and dev toggle UX

This commit is contained in:
2026-03-01 12:47:58 +01:00
parent 844cd3f58e
commit 5a3b0ace61
9 changed files with 176 additions and 22 deletions

View File

@@ -6,6 +6,19 @@ interface ServiceWorkerRegistrationOptions {
onError?: (error: Error) => void;
}
const DEV_SW_ENABLED_STORAGE_KEY = "stripstream:sw-dev-enabled";
export const isServiceWorkerEnabledInDev = (): boolean => {
if (typeof window === "undefined") return false;
if (process.env.NODE_ENV !== "development") return true;
return window.localStorage.getItem(DEV_SW_ENABLED_STORAGE_KEY) === "true";
};
export const setServiceWorkerEnabledInDev = (enabled: boolean): void => {
if (typeof window === "undefined" || process.env.NODE_ENV !== "development") return;
window.localStorage.setItem(DEV_SW_ENABLED_STORAGE_KEY, enabled ? "true" : "false");
};
/**
* Register the service worker with optional callbacks for update and success events
*/