Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Comment on lines +20 to 22
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README.md file still references the old environment variable name ENABLE_SW_IN_DEV in lines 331, 334, and 337. Since this comment mentions that "This behavior should be documented in README.md," the documentation should be updated to use NEXT_PUBLIC_ENABLE_SW_IN_DEV to match the code changes and prevent confusion for developers.

Suggested change
// 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.
// 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
// Set NEXT_PUBLIC_ENABLE_SW_IN_DEV only when you intentionally want to test PWA/offline behavior in development.

Copilot uses AI. Check for mistakes.
disable: isProduction ? false : !enableSwInDev,
});
Expand Down
9 changes: 6 additions & 3 deletions src/components/sw-register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading