Skip to content

Next config split#1720

Merged
simo6529 merged 2 commits intomainfrom
next-config-split
Jan 9, 2026
Merged

Next config split#1720
simo6529 merged 2 commits intomainfrom
next-config-split

Conversation

@simo6529
Copy link
Copy Markdown
Collaborator

@simo6529 simo6529 commented Jan 9, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Enabled runtime asset configuration, allowing dynamic selection of asset sources without environment changes or redeployment.
  • Refactor

    • Reorganized configuration management by extracting assets, versioning, security headers, and runtime configuration into dedicated modules for improved consistency and maintainability.

✏️ Tip: You can customize this high-level summary in your review settings.

Signed-off-by: Simo <simo@6529.io>
Signed-off-by: Simo <simo@6529.io>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 9, 2026

📝 Walkthrough

Walkthrough

The PR externalizes Next.js configuration logic from next.config.ts into dedicated, reusable modules for assets resolution, version computation, runtime configuration persistence/loading, and security headers, reducing inline implementations in favor of centralized configuration builders.

Changes

Cohort / File(s) Summary
Asset & Version Resolution
config/assets.ts, config/version.ts
New utility modules: resolveAssetsFlagFromEnv() reads S3 asset flag from environment; loadAssetsFlagAtRuntime() adds file-based fallback to .next/ASSETS_FROM_S3; computeVersionFromEnvOrGit() resolves version from env or Git HEAD with fallback.
Configuration Builders
config/nextConfig.ts, config/runtimeConfig.ts
sharedConfig() centralizes Next.js configuration with security headers, image optimization, webpack customization, and turbopack aliasing; persistBakedArtifacts() and loadBakedRuntimeConfig() manage runtime config persistence to .next/PUBLIC_RUNTIME.json with schema validation.
Type Refinement
config/securityHeaders.ts
Function parameter type updated: apiEndpoint now explicitly typed as string | undefined instead of inferred, preserving default behavior.
Configuration Orchestration
next.config.ts
Major refactoring: replaced 148 lines of embedded helper logic with imports from new config modules; now uses computeVersionFromEnvOrGit(), resolveAssetsFlagFromEnv(), loadBakedRuntimeConfig(), persistBakedArtifacts(), loadAssetsFlagAtRuntime(), and sharedConfig() for centralized, reusable configuration management.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Fix process.env use #1495 — Both PRs shift environment variable sourcing from direct process.env fallbacks to centralized config functions and publicEnv.
  • wip #1632 — Both PRs add serverExternalPackages field to Next.js configuration through modularized config builders.
  • Clean nextjs config file #1717 — Both PRs extract and centralize Next.js config helpers (createSecurityHeaders, sharedConfig, runtime config functions) from inline implementations into dedicated modules.

Suggested reviewers

  • prxt6529
  • ragnep

Poem

🐰 Hops through config with glee,
Extracting helpers wild and free,
From tangled files to modules clean,
The tidiest Next.js build I've seen!
Version, assets, headers aligned—
Reusable logic, perfectly designed!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main refactoring: extracting Next.js configuration logic from next.config.ts into separate modular files (config/assets.ts, config/version.ts, config/runtimeConfig.ts, config/nextConfig.ts, config/securityHeaders.ts).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jan 9, 2026

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
next.config.ts (1)

56-58: Type mismatch with persistBakedArtifacts parameter.

publicEnv here is parsed.data (the validated object), but persistBakedArtifacts in config/runtimeConfig.ts declares the parameter as string. This works because JSON.stringify handles both, but the type declaration should be corrected in runtimeConfig.ts for accuracy.

🤖 Fix all issues with AI agents
In @config/runtimeConfig.ts:
- Around line 4-21: persistBakedArtifacts currently swallows all errors and has
a wrong parameter type: change the publicEnv parameter from string to the proper
object type (e.g., Record<string, unknown> or the validated config interface) so
JSON.stringify serializes an object rather than double-serializing a prebuilt
string, and replace the empty catch with a proper error handler that catches
(err) and logs a clear, contextual error (including function name
persistBakedArtifacts and relevant params or err.message) and either rethrows or
surfaces the failure so callers like loadBakedRuntimeConfig can detect missing
artifacts.
🧹 Nitpick comments (2)
config/runtimeConfig.ts (1)

23-32: JSON parse errors are not wrapped with context.

Lines 26 and 28 call JSON.parse directly. If the file or environment variable contains malformed JSON, the raw parse error won't indicate which source failed. Consider wrapping with context for easier debugging.

Suggested improvement
 export function loadBakedRuntimeConfig(VERSION: string) {
   let baked = {};
   if (process.env["PUBLIC_RUNTIME"]) {
-    baked = JSON.parse(process.env["PUBLIC_RUNTIME"]);
+    try {
+      baked = JSON.parse(process.env["PUBLIC_RUNTIME"]);
+    } catch (e) {
+      throw new Error("Failed to parse PUBLIC_RUNTIME env variable", { cause: e });
+    }
   } else if (fs.existsSync(".next/PUBLIC_RUNTIME.json")) {
-    baked = JSON.parse(fs.readFileSync(".next/PUBLIC_RUNTIME.json", "utf8"));
+    try {
+      baked = JSON.parse(fs.readFileSync(".next/PUBLIC_RUNTIME.json", "utf8"));
+    } catch (e) {
+      throw new Error("Failed to parse .next/PUBLIC_RUNTIME.json", { cause: e });
+    }
   }
   const parsed = publicEnvSchema.safeParse({ ...baked, VERSION });
   if (!parsed.success) throw parsed.error;
   return parsed.data;
 }
config/version.ts (1)

3-9: Unused environment variable assignment.

Line 6 sets process.env["__LOG_ENV_ONCE__"] = "1" on every call to logOnceConfig, but this variable is never read anywhere. This appears to be dead code or an incomplete feature.

Suggested removal
 export function logOnceConfig(label: string, message: string) {
   if (!process.env[`__LOG_${label}_ONCE__`]) {
     process.env[`__LOG_${label}_ONCE__`] = "1";
-    process.env["__LOG_ENV_ONCE__"] = "1";
     console.log(`${label}: ${message}`);
   }
 }
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 95b00d8 and 7c5aae7.

📒 Files selected for processing (6)
  • config/assets.ts
  • config/nextConfig.ts
  • config/runtimeConfig.ts
  • config/securityHeaders.ts
  • config/version.ts
  • next.config.ts
🧰 Additional context used
📓 Path-based instructions (11)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursorrules)

**/*.{ts,tsx,js,jsx}: Do not include any comments in the code; it should be self-explanatory
Write correct, up-to-date, bug-free, fully componentized, secure, and efficient code
Include all required imports and ensure proper naming of key components
Use NextJS features that match the current version

**/*.{ts,tsx,js,jsx}: Remove unnecessary Effects. If the Effect's only job is to derive or sync internal state, calculate during render or use useMemo instead.
Use useEffectEvent for non-reactive logic inside Effects to read the latest props/state without turning them into dependencies or causing unnecessary re-runs.
Use explicit caching with "use cache" directive at the top of Server Components, routes, or functions. Configure cacheComponents: true in next.config.ts as needed.

**/*.{ts,tsx,js,jsx}: Remove unnecessary Effects; if the Effect only derives state, compute during render instead
Use useEffectEvent when listening to external events but needing the latest props/state without re-running the Effect
Move data fetching from client Effects to Server Components; mutations go through Server Actions ('use server')

Files:

  • config/nextConfig.ts
  • config/runtimeConfig.ts
  • config/version.ts
  • config/securityHeaders.ts
  • config/assets.ts
  • next.config.ts
{.env*,*.env,**/config/**}

📄 CodeRabbit inference engine (.cursor/rules/dev_workflow.mdc)

Configure Task Master behavior via environment variables: ANTHROPIC_API_KEY (required), MODEL, MAX_TOKENS, TEMPERATURE, DEBUG, LOG_LEVEL, DEFAULT_SUBTASKS, DEFAULT_PRIORITY, PROJECT_NAME, PROJECT_VERSION, PERPLEXITY_API_KEY, and PERPLEXITY_MODEL

Files:

  • config/nextConfig.ts
  • config/runtimeConfig.ts
  • config/version.ts
  • config/securityHeaders.ts
  • config/assets.ts
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (GEMINI.md)

Run npm run lint to ensure code satisfies ESLint (Next's Core Web Vitals + React Hooks). Code must pass linting before completing any task.

**/*.{js,ts,jsx,tsx}: Code must satisfy ESLint with Next's Core Web Vitals and React Hooks rules by running npm run lint
Do not add eslint-disable comments unless explicitly instructed; prefer refactors aligned with React 19.2, React Compiler, and Next.js 16 conventions

Files:

  • config/nextConfig.ts
  • config/runtimeConfig.ts
  • config/version.ts
  • config/securityHeaders.ts
  • config/assets.ts
  • next.config.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (GEMINI.md)

Use TypeScript with React functional components and hooks. Follow existing code style and naming conventions.

Files:

  • config/nextConfig.ts
  • config/runtimeConfig.ts
  • config/version.ts
  • config/securityHeaders.ts
  • config/assets.ts
  • next.config.ts
**/*.{tsx,ts}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript with React functional components and hooks

Files:

  • config/nextConfig.ts
  • config/runtimeConfig.ts
  • config/version.ts
  • config/securityHeaders.ts
  • config/assets.ts
  • next.config.ts
**/*.{ts,js}

📄 CodeRabbit inference engine (AGENTS.md)

When parsing Seize URLs or similar, fail fast if base origin is unavailable instead of falling back to placeholder origins

Files:

  • config/nextConfig.ts
  • config/runtimeConfig.ts
  • config/version.ts
  • config/securityHeaders.ts
  • config/assets.ts
  • next.config.ts
**/*.{tsx,ts,jsx,js}

📄 CodeRabbit inference engine (AGENTS.md)

Prefer direct named imports from React (useMemo, useRef, FC) over React. namespace usage

Files:

  • config/nextConfig.ts
  • config/runtimeConfig.ts
  • config/version.ts
  • config/securityHeaders.ts
  • config/assets.ts
  • next.config.ts
next.config.{js,ts,mjs,mts}

📄 CodeRabbit inference engine (GEMINI.md)

next.config.{js,ts,mjs,mts}: With Next.js 16, next lint is removed. Use the ESLint CLI driven by eslint-config-next (flat config). Remove any eslint options from next.config.*.
Enable React Compiler in next.config.ts once CI is green by setting reactCompiler: true to auto-memoize components and reduce manual useMemo/useCallback usage.

Files:

  • next.config.ts
{eslint.config.js,next.config.ts}

📄 CodeRabbit inference engine (AGENTS.md)

Use ESLint CLI driven by eslint-config-next (flat config) instead of next lint (removed in Next.js 16)

Files:

  • next.config.ts
next.config.ts

📄 CodeRabbit inference engine (AGENTS.md)

Enable React Compiler in next.config.ts by setting reactCompiler: true when CI is green

Files:

  • next.config.ts
next.config.{ts,js,mjs}

📄 CodeRabbit inference engine (AGENTS.md)

Remove any eslint options from next.config.* files in Next.js 16

Files:

  • next.config.ts
🧠 Learnings (12)
📓 Common learnings
Learnt from: CR
Repo: 6529-Collections/6529seize-frontend PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-30T14:32:19.360Z
Learning: Applies to next.config.{ts,js,mjs} : Remove any `eslint` options from `next.config.*` files in Next.js 16
Learnt from: CR
Repo: 6529-Collections/6529seize-frontend PR: 0
File: .cursorrules:0-0
Timestamp: 2025-11-25T08:35:58.729Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use NextJS features that match the current version
Learnt from: CR
Repo: 6529-Collections/6529seize-frontend PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-30T14:31:53.006Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use explicit caching with `"use cache"` directive at the top of Server Components, routes, or functions. Configure `cacheComponents: true` in `next.config.ts` as needed.
Learnt from: CR
Repo: 6529-Collections/6529seize-frontend PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-30T14:31:53.006Z
Learning: Applies to next.config.{js,ts,mjs,mts} : Enable React Compiler in `next.config.ts` once CI is green by setting `reactCompiler: true` to auto-memoize components and reduce manual `useMemo`/`useCallback` usage.
Learnt from: CR
Repo: 6529-Collections/6529seize-frontend PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-30T14:32:19.360Z
Learning: Applies to {eslint.config.js,next.config.ts} : Use ESLint CLI driven by `eslint-config-next` (flat config) instead of `next lint` (removed in Next.js 16)
Learnt from: CR
Repo: 6529-Collections/6529seize-frontend PR: 0
File: app/api/AGENTS.md:0-0
Timestamp: 2025-12-30T14:32:44.885Z
Learning: Applies to app/api/**/*.{ts,tsx} : Follow the project default responses (`NextResponse.json`) and reuse existing util modules instead of duplicating logic.
Learnt from: CR
Repo: 6529-Collections/6529seize-frontend PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-30T14:32:19.360Z
Learning: Applies to proxy.ts : Rename `middleware.ts` to `proxy.ts` for request boundary logic and export `proxy` function (Next.js 16+)
Learnt from: CR
Repo: 6529-Collections/6529seize-frontend PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-30T14:31:53.006Z
Learning: Applies to next.config.{js,ts,mjs,mts} : With Next.js 16, `next lint` is removed. Use the ESLint CLI driven by `eslint-config-next` (flat config). Remove any `eslint` options from `next.config.*`.
Learnt from: CR
Repo: 6529-Collections/6529seize-frontend PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-30T14:32:19.360Z
Learning: Applies to next.config.ts : Enable React Compiler in `next.config.ts` by setting `reactCompiler: true` when CI is green
📚 Learning: 2025-12-30T14:32:19.360Z
Learnt from: CR
Repo: 6529-Collections/6529seize-frontend PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-30T14:32:19.360Z
Learning: Applies to next.config.{ts,js,mjs} : Remove any `eslint` options from `next.config.*` files in Next.js 16

Applied to files:

  • config/nextConfig.ts
  • next.config.ts
📚 Learning: 2025-12-30T14:31:53.006Z
Learnt from: CR
Repo: 6529-Collections/6529seize-frontend PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-30T14:31:53.006Z
Learning: Applies to next.config.{js,ts,mjs,mts} : Enable React Compiler in `next.config.ts` once CI is green by setting `reactCompiler: true` to auto-memoize components and reduce manual `useMemo`/`useCallback` usage.

Applied to files:

  • config/nextConfig.ts
  • next.config.ts
📚 Learning: 2025-12-30T14:31:53.006Z
Learnt from: CR
Repo: 6529-Collections/6529seize-frontend PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-30T14:31:53.006Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use explicit caching with `"use cache"` directive at the top of Server Components, routes, or functions. Configure `cacheComponents: true` in `next.config.ts` as needed.

Applied to files:

  • config/nextConfig.ts
  • config/runtimeConfig.ts
  • config/assets.ts
  • next.config.ts
📚 Learning: 2025-12-30T14:32:19.360Z
Learnt from: CR
Repo: 6529-Collections/6529seize-frontend PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-30T14:32:19.360Z
Learning: Applies to next.config.ts : Enable React Compiler in `next.config.ts` by setting `reactCompiler: true` when CI is green

Applied to files:

  • config/nextConfig.ts
  • next.config.ts
📚 Learning: 2025-12-30T14:32:19.360Z
Learnt from: CR
Repo: 6529-Collections/6529seize-frontend PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-30T14:32:19.360Z
Learning: Applies to proxy.ts : Rename `middleware.ts` to `proxy.ts` for request boundary logic and export `proxy` function (Next.js 16+)

Applied to files:

  • config/nextConfig.ts
  • next.config.ts
📚 Learning: 2025-12-30T14:32:44.885Z
Learnt from: CR
Repo: 6529-Collections/6529seize-frontend PR: 0
File: app/api/AGENTS.md:0-0
Timestamp: 2025-12-30T14:32:44.885Z
Learning: Applies to app/api/**/*.{ts,tsx} : When needing custom headers or timeouts for external requests, pass them via the `@/lib/security/urlGuard` helper options rather than re-implementing your own wrapper.

Applied to files:

  • config/securityHeaders.ts
📚 Learning: 2025-11-25T08:35:58.729Z
Learnt from: CR
Repo: 6529-Collections/6529seize-frontend PR: 0
File: .cursorrules:0-0
Timestamp: 2025-11-25T08:35:58.729Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use NextJS features that match the current version

Applied to files:

  • next.config.ts
📚 Learning: 2025-12-30T14:31:53.006Z
Learnt from: CR
Repo: 6529-Collections/6529seize-frontend PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-30T14:31:53.006Z
Learning: Applies to next.config.{js,ts,mjs,mts} : With Next.js 16, `next lint` is removed. Use the ESLint CLI driven by `eslint-config-next` (flat config). Remove any `eslint` options from `next.config.*`.

Applied to files:

  • next.config.ts
📚 Learning: 2025-12-30T14:31:53.006Z
Learnt from: CR
Repo: 6529-Collections/6529seize-frontend PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-30T14:31:53.006Z
Learning: Fix issues with modernization aligned to React 19.2, React Compiler, and Next.js 16 conventions. Do not add `// eslint-disable` comments unless explicitly instructed.

Applied to files:

  • next.config.ts
📚 Learning: 2025-12-30T14:32:19.360Z
Learnt from: CR
Repo: 6529-Collections/6529seize-frontend PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-30T14:32:19.360Z
Learning: Applies to {eslint.config.js,next.config.ts} : Use ESLint CLI driven by `eslint-config-next` (flat config) instead of `next lint` (removed in Next.js 16)

Applied to files:

  • next.config.ts
📚 Learning: 2025-12-30T14:32:37.305Z
Learnt from: CR
Repo: 6529-Collections/6529seize-frontend PR: 0
File: __tests__/AGENTS.md:0-0
Timestamp: 2025-12-30T14:32:37.305Z
Learning: Applies to __tests__/**/*.{ts,tsx,js},!**/__tests__/**,!**/__mocks__/**,!**/*.d.ts : Use one import per module with ordering: external → internal → types, no duplicates

Applied to files:

  • next.config.ts
🧬 Code graph analysis (2)
config/nextConfig.ts (3)
config/env.ts (1)
  • publicEnv (7-7)
config/env.schema.ts (1)
  • PublicEnv (129-129)
config/securityHeaders.ts (1)
  • createSecurityHeaders (1-46)
config/runtimeConfig.ts (2)
config/env.ts (1)
  • publicEnv (7-7)
config/env.schema.ts (1)
  • publicEnvSchema (10-127)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (7)
config/assets.ts (1)

3-16: LGTM with minor nit.

The logic is correct and the file-based fallback pattern aligns well with the runtime config loading approach. Minor observation: .toString() on lines 5 and 11 is unnecessary since process.env values are already strings, though it doesn't cause harm.

config/securityHeaders.ts (1)

1-1: LGTM!

The explicit type annotation with a default empty string improves type safety and ensures the CSP connect-src directive doesn't contain "undefined" as a literal string.

config/version.ts (1)

11-25: LGTM!

The version resolution logic with git fallback is well-structured. The fail-fast approach with a sensible default ("6529seize") when git is unavailable handles CI/CD and containerized environments appropriately.

next.config.ts (1)

33-125: Well-structured modularization.

The refactoring cleanly separates concerns: version computation, asset flag resolution, runtime config persistence/loading, and shared config building are now in dedicated modules. The phase-based configuration logic is preserved correctly, and the fail-fast validation approach at both build and runtime phases is appropriate.

config/nextConfig.ts (3)

64-64: Minification is disabled.

config.optimization.minimize = false disables minification for client bundles. Combined with productionBrowserSourceMaps: true, this significantly increases bundle size. Verify this is intentional for debugging purposes and not accidentally left from development.


6-78: Good centralization of shared Next.js config.

The sharedConfig function consolidates common configuration that was previously duplicated or inline. The reactCompiler: true setting aligns with the learnings for Next.js 16. Security headers are properly integrated via createSecurityHeaders.


67-75: All Turbopack alias paths are correctly configured and files exist.

The stub files and alias target files referenced in the resolveAlias configuration are present and committed:

  • stubs/empty.js exists (22 bytes)
  • lib/storage/idb-keyval.ts exists (10,390 bytes)

No action needed.

Comment thread config/runtimeConfig.ts
@simo6529 simo6529 merged commit a75a65f into main Jan 9, 2026
10 checks passed
@simo6529 simo6529 deleted the next-config-split branch January 9, 2026 13:06
@coderabbitai coderabbitai Bot mentioned this pull request Feb 25, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants