Skip to content

refactor: extract generateSsrEntry and generateBrowserEntry into entries/#377

Merged
james-elicx merged 1 commit intomainfrom
refactor/extract-ssr-browser-entries
Mar 9, 2026
Merged

refactor: extract generateSsrEntry and generateBrowserEntry into entries/#377
james-elicx merged 1 commit intomainfrom
refactor/extract-ssr-browser-entries

Conversation

@james-elicx
Copy link
Collaborator

Summary

  • Extracts generateSsrEntry and generateBrowserEntry from server/app-dev-server.ts into new dedicated modules under packages/vinext/src/entries/
  • app-dev-server.ts re-exports them from the new locations, keeping the public API identical
  • No snapshot changes — all 10 entry-template tests pass unchanged

Motivation

Part of the refactor tracked in #253. app-dev-server.ts is ~3200 lines; moving the two self-contained entry generators (no parameters, no closure dependencies) into entries/ is the cleanest first step.

Changes

File Change
packages/vinext/src/entries/app-ssr-entry.ts New — contains generateSsrEntry()
packages/vinext/src/entries/app-browser-entry.ts New — contains generateBrowserEntry()
packages/vinext/src/server/app-dev-server.ts Removed ~787 lines of function bodies; added 2 re-export lines

Follow-ups (not in this PR)

  • generateRscEntry (~1860 lines) → entries/app-rsc-entry.ts
  • generateServerEntry / generateClientEntry from index.ts

…ies/

Moves generateSsrEntry (app-ssr-entry.ts) and generateBrowserEntry
(app-browser-entry.ts) out of the 3,215-line app-dev-server.ts into a new
entries/ directory, as described in issue #253.

app-dev-server.ts re-exports both functions so all existing import sites
(including entry-templates.test.ts) continue to work without changes.

All 10 entry-template snapshot tests pass unchanged — generated output is
byte-for-byte identical to before the move.
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 9, 2026

Open in StackBlitz

npm i https://pkg.pr.new/vinext@377

commit: 77ff817

@github-actions
Copy link

github-actions bot commented Mar 9, 2026

Example Preview Production Original
app-router-cloudflare preview production
pages-router-cloudflare preview production
app-router-playground preview production original
realworld-api-rest preview production
nextra-docs-template preview production
benchmarks preview production
hackernews preview production original

@james-elicx
Copy link
Collaborator Author

/bigbonk review

@james-elicx james-elicx marked this pull request as ready for review March 9, 2026 13:20
Copy link
Contributor

@ask-bonk ask-bonk bot left a comment

Choose a reason for hiding this comment

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

Clean extraction. I verified the following:

Correctness of the move:

  • Diffed the removed function bodies from app-dev-server.ts against the new files line-by-line. The template string contents are byte-identical. The only differences are the function declaration + JSDoc wrappers, which are now in the new files as expected.

Re-export correctness:

  • app-dev-server.ts:2428-2429 re-exports both generateSsrEntry and generateBrowserEntry. index.ts imports both from ./server/app-dev-server.js (unchanged). The chain works — all existing import sites resolve without changes.

No closure dependencies:

  • Both functions are self-contained string-returning generators with no parameters and no references to module-level variables from app-dev-server.ts. The extraction is safe.

Tests:

  • All 10 entry-templates.test.ts tests pass (snapshot comparisons of the generated code).
  • All 209 app-router.test.ts tests pass, including the tests at lines 2678-2799 that specifically import generateSsrEntry/generateBrowserEntry from app-dev-server.js and inspect their output.
  • Typecheck passes clean.

No dev/prod parity concerns:

  • These functions generate virtual module source code (template strings). They don't contain request handling logic. The prod server and worker entry are unaffected.

Looks good.

@ask-bonk
Copy link
Contributor

ask-bonk bot commented Mar 9, 2026

Reviewed and approved PR #377. Here's the summary:

Verdict: Approved

The extraction is a clean code move with no behavioral changes:

  • Byte-identical function bodies — diffed the removed code from app-dev-server.ts against the new files; the template string contents match exactly.
  • Re-exports preserve APIapp-dev-server.ts re-exports both functions, so all existing import sites (index.ts, tests) resolve without changes.
  • No closure dependencies — both functions are self-contained string generators with no parameters and no references to module-level state in the original file.
  • All tests pass — 10/10 entry-template snapshot tests, 209/209 app-router tests, and typecheck is clean.
  • No dev/prod parity concerns — these functions generate virtual module source code (template strings), not request handling logic.

github run

@james-elicx james-elicx merged commit 01202a9 into main Mar 9, 2026
25 checks passed
@james-elicx james-elicx deleted the refactor/extract-ssr-browser-entries branch March 9, 2026 13:22
james-elicx added a commit that referenced this pull request Mar 9, 2026
…ntEntry into entries/

Move the three remaining large code generators out of app-dev-server.ts and
index.ts into dedicated modules under src/entries/, matching the pattern
established by PR #377 for generateSsrEntry and generateBrowserEntry.

- entries/app-rsc-entry.ts       — generateRscEntry() (~2400 lines)
- entries/pages-server-entry.ts  — generateServerEntry() (~985 lines)
- entries/pages-client-entry.ts  — generateClientEntry() (~85 lines)
- entries/pages-entry-helpers.ts — shared findFileWithExts() helper

app-dev-server.ts and index.ts become thin re-export/delegation wrappers.
All 10 entry-template snapshot tests pass unchanged.
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.

Refactor: Extract template string code generation from index.ts and app-dev-server.ts into separate modules

1 participant