From 5b227b369277e77c86e4180fe4e83ba1548b7691 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Feb 2026 07:14:08 +0000 Subject: [PATCH 1/3] Initial plan From 2abd4259b26c8e7ee0f679c6678ddb6e879f5627 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Feb 2026 07:15:32 +0000 Subject: [PATCH 2/3] Fix environment variable inconsistency in service worker registration - Check both ENABLE_SW_IN_DEV and NEXT_PUBLIC_ENABLE_SW_IN_DEV - Prioritize ENABLE_SW_IN_DEV (matching next.config.ts) with NEXT_PUBLIC_ as fallback - Update logger message to document both options for backwards compatibility Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> --- src/components/sw-register.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/sw-register.tsx b/src/components/sw-register.tsx index 8ceb6cb..b4a4aeb 100644 --- a/src/components/sw-register.tsx +++ b/src/components/sw-register.tsx @@ -25,13 +25,18 @@ export function ServiceWorkerRegister() { return; } - // In development, only register if explicitly enabled (NEXT_PUBLIC_ENABLE_SW_IN_DEV=true) + // In development, only register if explicitly enabled (ENABLE_SW_IN_DEV=true) // 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", - }); + const enableSwInDev = + process.env.ENABLE_SW_IN_DEV ?? process.env.NEXT_PUBLIC_ENABLE_SW_IN_DEV; + if (isDev && enableSwInDev !== "true") { + logger.dev( + "Service worker is disabled in development. Enable with ENABLE_SW_IN_DEV=true (or NEXT_PUBLIC_ENABLE_SW_IN_DEV=true for backwards compatibility)", + { + context: "ServiceWorkerRegister", + }, + ); return; } From eadda8881af04ee2b8ea7e4528feeb3ccf8d9737 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Feb 2026 07:16:36 +0000 Subject: [PATCH 3/3] Use consistent environment variable NEXT_PUBLIC_ENABLE_SW_IN_DEV in both config and component - Update next.config.ts to use NEXT_PUBLIC_ENABLE_SW_IN_DEV instead of ENABLE_SW_IN_DEV - Update comments in next.config.ts to reflect the correct variable name - Simplify sw-register.tsx to only check NEXT_PUBLIC_ENABLE_SW_IN_DEV - This ensures users only need to set one environment variable for both build-time and runtime SW control Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> --- next.config.ts | 6 +++--- src/components/sw-register.tsx | 8 +++----- 2 files changed, 6 insertions(+), 8 deletions(-) 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 b4a4aeb..b6ba8fc 100644 --- a/src/components/sw-register.tsx +++ b/src/components/sw-register.tsx @@ -25,14 +25,12 @@ export function ServiceWorkerRegister() { return; } - // In development, only register if explicitly enabled (ENABLE_SW_IN_DEV=true) + // In development, only register if explicitly enabled (NEXT_PUBLIC_ENABLE_SW_IN_DEV=true) // In production, service worker is always enabled and generated at build time const isDev = process.env.NODE_ENV === "development"; - const enableSwInDev = - process.env.ENABLE_SW_IN_DEV ?? process.env.NEXT_PUBLIC_ENABLE_SW_IN_DEV; - if (isDev && enableSwInDev !== "true") { + if (isDev && process.env.NEXT_PUBLIC_ENABLE_SW_IN_DEV !== "true") { logger.dev( - "Service worker is disabled in development. Enable with ENABLE_SW_IN_DEV=true (or NEXT_PUBLIC_ENABLE_SW_IN_DEV=true for backwards compatibility)", + "Service worker is disabled in development. Enable with NEXT_PUBLIC_ENABLE_SW_IN_DEV=true", { context: "ServiceWorkerRegister", },