[PR #408] [MERGED] feat: support generateBuildId in next.config and inject build ID at runtime #550

Closed
opened 2026-05-06 13:08:43 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/408
Author: @james-elicx
Created: 3/10/2026
Status: Merged
Merged: 3/10/2026
Merged by: @james-elicx

Base: mainHead: opencode/lucky-island


📝 Commits (6)

  • 04c2f34 feat: support generateBuildId in next.config and inject build ID at runtime
  • baf0c7e regen snaps
  • 56d93fe refactor: extract safeUUID helper and drop buildId param from createSSRHandler
  • aaa5089 regen snaps
  • a71c0cd fix: stabilize entry-templates snapshot by setting generateBuildId in pages-basic fixture
  • 3aaa94c fix: move buildId to NextURL to match Next.js API surface

📊 Changes

10 files changed (+208 additions, -2 deletions)

View changed files

📝 packages/vinext/src/build/static-export.ts (+1 -0)
📝 packages/vinext/src/config/next-config.ts (+57 -0)
📝 packages/vinext/src/entries/pages-server-entry.ts (+7 -1)
📝 packages/vinext/src/index.ts (+3 -0)
📝 packages/vinext/src/server/dev-server.ts (+1 -0)
📝 packages/vinext/src/shims/server.ts (+19 -0)
📝 tests/__snapshots__/entry-templates.test.ts.snap (+4 -1)
📝 tests/fixtures/pages-basic/next.config.mjs (+1 -0)
📝 tests/next-config.test.ts (+69 -0)
📝 tests/shims.test.ts (+46 -0)

📄 Description

Summary

  • Adds generateBuildId support to next.config — calls the function at build/dev start, falls back to a random UUID (ad-blocker-safe, no "ad" substring) when not provided or when the function returns null
  • Injects the resolved ID as process.env.__VINEXT_BUILD_ID via Vite define so it's available at runtime across all environments
  • Embeds buildId in __NEXT_DATA__ for Pages Router (dev server, production server, and static export)
  • Adds NextRequest.buildId accessor in the next/server shim for deployment-skew detection in middleware
  • Matches Next.js error messages exactly (generateBuildId did not return a string, generateBuildId returned an empty string)

Tests

10 new tests in tests/next-config.test.ts (ported from the Next.js integration test suite), 2 new tests in tests/shims.test.ts — all passing.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/408 **Author:** [@james-elicx](https://github.com/james-elicx) **Created:** 3/10/2026 **Status:** ✅ Merged **Merged:** 3/10/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `opencode/lucky-island` --- ### 📝 Commits (6) - [`04c2f34`](https://github.com/cloudflare/vinext/commit/04c2f34cf034ae84a67869a5ad5797d5f3a2827d) feat: support generateBuildId in next.config and inject build ID at runtime - [`baf0c7e`](https://github.com/cloudflare/vinext/commit/baf0c7ebd67546c77f083a60ee0b8986ca5470c5) regen snaps - [`56d93fe`](https://github.com/cloudflare/vinext/commit/56d93fe2ffedb974a53535741530fd93e8cdfb4a) refactor: extract safeUUID helper and drop buildId param from createSSRHandler - [`aaa5089`](https://github.com/cloudflare/vinext/commit/aaa5089f6312f0088a759994b5d9bde9feeffe91) regen snaps - [`a71c0cd`](https://github.com/cloudflare/vinext/commit/a71c0cd3a641c42e9fb26bfbead417da8cffed20) fix: stabilize entry-templates snapshot by setting generateBuildId in pages-basic fixture - [`3aaa94c`](https://github.com/cloudflare/vinext/commit/3aaa94cc925657c3caab9ce53d31aa5efa7895ac) fix: move buildId to NextURL to match Next.js API surface ### 📊 Changes **10 files changed** (+208 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/build/static-export.ts` (+1 -0) 📝 `packages/vinext/src/config/next-config.ts` (+57 -0) 📝 `packages/vinext/src/entries/pages-server-entry.ts` (+7 -1) 📝 `packages/vinext/src/index.ts` (+3 -0) 📝 `packages/vinext/src/server/dev-server.ts` (+1 -0) 📝 `packages/vinext/src/shims/server.ts` (+19 -0) 📝 `tests/__snapshots__/entry-templates.test.ts.snap` (+4 -1) 📝 `tests/fixtures/pages-basic/next.config.mjs` (+1 -0) 📝 `tests/next-config.test.ts` (+69 -0) 📝 `tests/shims.test.ts` (+46 -0) </details> ### 📄 Description ## Summary - Adds `generateBuildId` support to `next.config` — calls the function at build/dev start, falls back to a random UUID (ad-blocker-safe, no \"ad\" substring) when not provided or when the function returns `null` - Injects the resolved ID as `process.env.__VINEXT_BUILD_ID` via Vite `define` so it's available at runtime across all environments - Embeds `buildId` in `__NEXT_DATA__` for Pages Router (dev server, production server, and static export) - Adds `NextRequest.buildId` accessor in the `next/server` shim for deployment-skew detection in middleware - Matches Next.js error messages exactly (`generateBuildId did not return a string`, `generateBuildId returned an empty string`) ## Tests 10 new tests in `tests/next-config.test.ts` (ported from the Next.js integration test suite), 2 new tests in `tests/shims.test.ts` — all passing. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:08:43 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#550
No description provided.