diff --git a/next.config.ts b/next.config.ts index dc96d06..0afc36a 100644 --- a/next.config.ts +++ b/next.config.ts @@ -3,7 +3,7 @@ import type { NextConfig } from "next"; import withSerwistInit from "@serwist/next"; const isProduction = process.env.NODE_ENV === "production"; -const enableSwInDev = process.env.ENABLE_SW_IN_DEV === "true"; +const enableSwInDev = process.env.NEXT_PUBLIC_ENABLE_SW_IN_DEV === "true"; const withSerwist = withSerwistInit({ // Source TypeScript service worker implementation @@ -17,8 +17,8 @@ const withSerwist = withSerwistInit({ // so team members understand which files are safe to edit/commit. swDest: "public/sw.js", // By default, service workers are disabled outside production to avoid caching issues during development. - // To test PWA / offline functionality locally, start Next.js in development mode with ENABLE_SW_IN_DEV="true" - // Example: ENABLE_SW_IN_DEV="true" npm run dev + // To test PWA / offline functionality locally, start Next.js in development mode with NEXT_PUBLIC_ENABLE_SW_IN_DEV="true" + // Example: NEXT_PUBLIC_ENABLE_SW_IN_DEV="true" npm run dev // This behavior should be documented in README.md for team members testing PWA features. disable: isProduction ? false : !enableSwInDev, }); diff --git a/src/components/sw-register.tsx b/src/components/sw-register.tsx index 8ceb6cb..b6ba8fc 100644 --- a/src/components/sw-register.tsx +++ b/src/components/sw-register.tsx @@ -29,9 +29,12 @@ export function ServiceWorkerRegister() { // In production, service worker is always enabled and generated at build time const isDev = process.env.NODE_ENV === "development"; if (isDev && process.env.NEXT_PUBLIC_ENABLE_SW_IN_DEV !== "true") { - logger.dev("Service worker is disabled in development. Enable with NEXT_PUBLIC_ENABLE_SW_IN_DEV=true", { - context: "ServiceWorkerRegister", - }); + logger.dev( + "Service worker is disabled in development. Enable with NEXT_PUBLIC_ENABLE_SW_IN_DEV=true", + { + context: "ServiceWorkerRegister", + }, + ); return; }