Unify service worker environment variable to NEXT_PUBLIC_ENABLE_SW_IN_DEV#269
Unify service worker environment variable to NEXT_PUBLIC_ENABLE_SW_IN_DEV#269
Conversation
- 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>
…oth 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>
There was a problem hiding this comment.
Pull request overview
This pull request unifies the environment variable used to control service worker behavior in development mode. Previously, the codebase used ENABLE_SW_IN_DEV in build-time configuration and NEXT_PUBLIC_ENABLE_SW_IN_DEV in runtime registration, requiring developers to set both variables. The PR standardizes on NEXT_PUBLIC_ENABLE_SW_IN_DEV for both contexts.
Changes:
- Updated
next.config.tsto useNEXT_PUBLIC_ENABLE_SW_IN_DEVinstead ofENABLE_SW_IN_DEVfor build-time service worker generation control - Updated comments in
next.config.tsto reference the unified variable name - Reformatted a logger call in
sw-register.tsxfor better readability (no functional change)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| next.config.ts | Changed environment variable from ENABLE_SW_IN_DEV to NEXT_PUBLIC_ENABLE_SW_IN_DEV and updated associated comments |
| src/components/sw-register.tsx | Reformatted multi-line logger.dev call for consistency (no functional changes) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // 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. |
There was a problem hiding this comment.
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.
| // 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. |
* chore: update dependencies and improve error handling - Updated package dependencies in package.json: - Upgraded @redocly/cli from ^1.31.0 to 2.15.1 - Upgraded jsdom from ^27.4.0 to 28.0.0 - Added glob as a dependency with version ^13.0.1 - Added node-domexception as a dependency with version ^2.0.2 - Added source-map as a dependency with version ^0.8.0-beta.0 - Increased timeout for authentication service requests from 5s to 15s in save-token route to handle slow backends and network latency. - Enhanced error handling for connection issues in save-token route, logging specific error codes and providing user-friendly messages. - Added conditional service worker registration in development mode based on ENABLE_SW_IN_DEV environment variable. - Improved session management in Supabase middleware by clearing invalid session cookies when token refresh fails and logging the error. * Address PR review feedback: improve error handling and dependency management (#265) * Initial plan * fix: address PR review feedback on error handling and dependencies Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> * refactor: optimize middleware error detection Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> * Address PR review feedback: enhance error handling and fix redundant logic (#266) * Initial plan * Address PR review: add ECONNREFUSED error code and remove redundant checks Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> * Address review feedback: safe error handling and remove deprecated dependency (#267) * Initial plan * fix: improve error handling and remove deprecated package Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> * Replace string-based error matching with structured error detection in middleware (#268) * Initial plan * Improve error handling with structured properties and add npm version requirement Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> * Optimize error handling: move constants to module scope and improve type safety Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> * Unify service worker environment variable to NEXT_PUBLIC_ENABLE_SW_IN_DEV (#269) * Initial plan * 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> * 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> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> * Fix environment variable documentation and glob version mismatch (#270) * Initial plan * Fix README and package.json per review feedback Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
The service worker control used inconsistent environment variables:
ENABLE_SW_IN_DEVinnext.config.tsfor build-time generation andNEXT_PUBLIC_ENABLE_SW_IN_DEVinsw-register.tsxfor runtime registration. This required developers to set both variables.Changes:
ENABLE_SW_IN_DEVtoNEXT_PUBLIC_ENABLE_SW_IN_DEVfor build-time SW generation controlNEXT_PUBLIC_ENABLE_SW_IN_DEVfor runtime registration (no change needed)Developers now set one variable to control both build-time and runtime behavior:
The
NEXT_PUBLIC_prefix is required for client-side access in Next.js, and using it innext.config.ts(server-side) works correctly as all environment variables are available at build time.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.