[PR #1085] [CLOSED] refactor(entries): dedupe ISR wrapper codegen and config serialization #1083

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

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/1085
Author: @james-elicx
Created: 5/5/2026
Status: Closed

Base: mainHead: refactor/entries-codegen-helpers


📝 Commits (2)

  • ce9c7be refactor(entries): dedupe ISR wrapper codegen and config serialization
  • f1bee9b refactor(entries): address review nits

📊 Changes

3 files changed (+193 additions, -57 deletions)

View changed files

📝 packages/vinext/src/entries/app-rsc-entry.ts (+34 -15)
📝 packages/vinext/src/entries/pages-server-entry.ts (+12 -42)
📝 packages/vinext/src/entries/runtime-entry-module.ts (+147 -0)

📄 Description

Summary

Pure refactor of the entry-template generators to consolidate the bits that pages-server-entry.ts and app-rsc-entry.ts copy-pasted from each other:

  • A. ISR wrapperspages-server-entry.ts emitted four thin forwarder functions (isrGet / isrSet / isrCacheKey / triggerBackgroundRegeneration) over the shared __sharedIsr* imports. Extracted to generateIsrWrapperCode() in runtime-entry-module.ts so future entries can reuse the block.
  • B. Config serialization — both generators serialized the same Resolved­NextConfig slice (basePath, trailingSlash, redirects, rewrites, headers, expireTime, i18n) via near-identical JSON.stringify chains. Extracted as two helpers in runtime-entry-module.ts:
    • serializePagesConfig() returns the compound vinextConfigJson object plus the narrower i18nConfigJson projection consumed by the SSR entry.
    • serializeAppConfig() returns per-field JSON literals matching the App Router RSC entry's __basePath / __configRedirects / __expireTime style. The existing DEFAULT_EXPIRE_TIME stays in app-rsc-entry.ts and is passed in.

The emitted runtime code is byte-identical to before (each replacement re-derives the same JSON.stringify chain on the same input). Verified by inspecting the per-field diff plus a full pass of tests/app-router.test.ts and tests/pages-router.test.ts (508/508 passing; one teardown-hook flake unrelated to this change). Follow-up to #1058 and #1079.

Files changed

  • packages/vinext/src/entries/runtime-entry-module.ts — new generateIsrWrapperCode(), serializePagesConfig(), serializeAppConfig(), and a private EntryConfigInput type.
  • packages/vinext/src/entries/pages-server-entry.ts — calls the two helpers.
  • packages/vinext/src/entries/app-rsc-entry.ts — calls serializeAppConfig(); the bp / ts / redirects / etc. locals collapse into the destructured JSON literals.

Test plan

  • pnpm vp test run tests/app-router.test.ts tests/pages-router.test.ts — 508/508 passing.
  • pnpm fmt --write clean.
  • pnpm knip clean (no unused exports).
  • tsc --noEmit clean.
  • Diff inspection: each replaced JSON.stringify(x) reduces to the same chain on the same input, so emitted-string output is byte-identical.

🤖 Generated with Claude Code


🔄 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/1085 **Author:** [@james-elicx](https://github.com/james-elicx) **Created:** 5/5/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `refactor/entries-codegen-helpers` --- ### 📝 Commits (2) - [`ce9c7be`](https://github.com/cloudflare/vinext/commit/ce9c7be4e95cfe84c9ae77e8d0bdc770d73394bb) refactor(entries): dedupe ISR wrapper codegen and config serialization - [`f1bee9b`](https://github.com/cloudflare/vinext/commit/f1bee9b2d90b3fc3f271f894f1e670f7ab92dfc6) refactor(entries): address review nits ### 📊 Changes **3 files changed** (+193 additions, -57 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/entries/app-rsc-entry.ts` (+34 -15) 📝 `packages/vinext/src/entries/pages-server-entry.ts` (+12 -42) 📝 `packages/vinext/src/entries/runtime-entry-module.ts` (+147 -0) </details> ### 📄 Description ## Summary Pure refactor of the entry-template generators to consolidate the bits that pages-server-entry.ts and app-rsc-entry.ts copy-pasted from each other: - **A. ISR wrappers** — `pages-server-entry.ts` emitted four thin forwarder functions (`isrGet` / `isrSet` / `isrCacheKey` / `triggerBackgroundRegeneration`) over the shared `__sharedIsr*` imports. Extracted to `generateIsrWrapperCode()` in `runtime-entry-module.ts` so future entries can reuse the block. - **B. Config serialization** — both generators serialized the same Resolved­NextConfig slice (basePath, trailingSlash, redirects, rewrites, headers, expireTime, i18n) via near-identical `JSON.stringify` chains. Extracted as two helpers in `runtime-entry-module.ts`: - `serializePagesConfig()` returns the compound `vinextConfigJson` object plus the narrower `i18nConfigJson` projection consumed by the SSR entry. - `serializeAppConfig()` returns per-field JSON literals matching the App Router RSC entry's `__basePath` / `__configRedirects` / `__expireTime` style. The existing `DEFAULT_EXPIRE_TIME` stays in `app-rsc-entry.ts` and is passed in. The emitted runtime code is byte-identical to before (each replacement re-derives the same `JSON.stringify` chain on the same input). Verified by inspecting the per-field diff plus a full pass of `tests/app-router.test.ts` and `tests/pages-router.test.ts` (508/508 passing; one teardown-hook flake unrelated to this change). Follow-up to #1058 and #1079. ### Files changed - `packages/vinext/src/entries/runtime-entry-module.ts` — new `generateIsrWrapperCode()`, `serializePagesConfig()`, `serializeAppConfig()`, and a private `EntryConfigInput` type. - `packages/vinext/src/entries/pages-server-entry.ts` — calls the two helpers. - `packages/vinext/src/entries/app-rsc-entry.ts` — calls `serializeAppConfig()`; the `bp` / `ts` / `redirects` / etc. locals collapse into the destructured JSON literals. ## Test plan - [x] `pnpm vp test run tests/app-router.test.ts tests/pages-router.test.ts` — 508/508 passing. - [x] `pnpm fmt --write` clean. - [x] `pnpm knip` clean (no unused exports). - [x] `tsc --noEmit` clean. - [x] Diff inspection: each replaced `JSON.stringify(x)` reduces to the same chain on the same input, so emitted-string output is byte-identical. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:11:53 +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#1083
No description provided.