fix(start-plugin-core): respect Vite root when prerendering #8826
main fromrefs/pull/8826/head·opened 🎯 Changes#
Fixes #8825 (#8824 is the same report).
Prerender ignored Vite's root, so it broke when root isn't the cwd:
vite.preview()now getsroot: viteConfig.root- client output dir (prerender + post-build) and the preview server's server entry dir are resolved against
config.root, soTSS_CLIENT_OUTPUT_DIRis absolute too
Added a test in prerender-vite.test.ts (fails on main).
AI disclosure: written with an AI assistant, reviewed and tested by me.
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested code changes locally with the relevant test commands, or tests do not apply to this pull request.
- I fully understand the code in this pull request, including any code generated with AI assistance.
nx run-many -p @tanstack/start-plugin-core -t test:unit test:eslint test:types: 873 passed, eslint and types clean.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
Summary by CodeRabbit#
- Bug Fixes
- Prerendering now correctly locates client and server build outputs when Vite uses a custom root directory.
- The preview server now uses the server environment’s configured root, helping ensure prerendered pages are served from the expected build output.
- Relative client output directories are resolved against the client environment’s root, improving consistency across Vite configurations.
- 1
Codex Review Summary#
This comment shows the latest Codex review activity on this pull request.
Review Status Commit Review trigger 📝 Code Review ⚠️ Failed 2026-10-27T21:34:38.601105Z
We couldn’t complete this review. Comment@codex reviewto try again.aa7de83PR opened ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review" or "@codex security review".
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
No actionable comments were generated in the recent review.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: TanStack/router
- Branch: main
- File: .coderabbit.yaml
- Commit: da2adec
- Layers: Repository YAML
- Review profile: CHILL
- Plan: Advanced
- Run ID:
69c9f76f-2431-407d-b3d3-613610f8e18e
Commits-
Reviewing files that changed from the base of the PR and between da2adec76dbe6c0da6d6a0d5640f7b9388217f45 and aa7de8392213a4bdaa49c0048b2e4432464af20d.
Files selected for processing: 5-
.changeset/start-prerender-vite-root.mdpackages/start-plugin-core/src/vite/post-server-build.tspackages/start-plugin-core/src/vite/prerender.tspackages/start-plugin-core/src/vite/preview-server-plugin/plugin.tspackages/start-plugin-core/tests/prerender-vite.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
Walkthrough
-
Prerendering now passes Vite’s root to the preview server and resolves client and server output directories relative to their configured roots.
Changes: Vite-root-aware prerendering
Priority:Layer / File(s) Summary Resolve prerender paths against Vite roots
packages/start-plugin-core/src/vite/prerender.ts,packages/start-plugin-core/src/vite/post-server-build.ts,packages/start-plugin-core/src/vite/preview-server-plugin/plugin.ts,packages/start-plugin-core/tests/prerender-vite.test.ts,.changeset/start-prerender-vite-root.mdThe preview configuration now receives the Vite root. Client and server output directories are resolved against their respective roots. A test checks the preview root and resolved client output path. The changeset records the prerender path changes. NormalEstimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related issues
- Issue 8824 describes the same prerender failures when the Vite root differs from the working directory. This change updates the preview root and output path resolution.
Suggested labels:
package: start-plugin-core
Merge Risk:
Minimal · up toaa7de-
The root-aware prerendering changes are ready to merge, subject to normal checks.
Pre-merge checks:
4 · 1-
Failed checks: 1 warningCheck name Status Explanation Resolution Docstring Coverage Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within survi… Write docstrings for the functions missing them to satisfy the coverage threshold. Passed checks: 4 passed-
Check name Status Explanation Description check The description includes all required sections, explains the Vite root fix, reports testing results, discloses AI assistance, and includes a changeset. One understanding checklist item remains uncheck… Title check The title clearly and concisely describes the main change: making start-plugin-core prerendering respect Vite's configured root. Linked Issues check Directly linked issue #8825requires prerender to honor Vite's root when it differs from the cwd. The diff from merge base da2adec to head aa7de83 covers each of the three failure points named in the …Out of Scope Changes check All changed files relate to the #8825fix:
- src/vite/prerender.ts: root passed to vite.preview() and client outDir resolved against the root. Both are in the linked objectives.
- src/vite/preview-ser…Full details: Description check
-
Explanation
The description includes all required sections, explains the Vite root fix, reports testing results, discloses AI assistance, and includes a changeset. One understanding checklist item remains unchecked, but the description is otherwise complete.
Full details: Linked Issues check
-
Explanation
Directly linked issue
#8825requires prerender to honor Vite's root when it differs from the cwd. The diff from merge base da2adec to head aa7de83 covers each of the three failure points named in the issue:- src/vite/prerender.ts, startPreviewServer: vite.preview() now receives root: viteConfig.root, so the preview config no longer takes root from process.cwd(). This matches the issue's suggested fix.
- src/vite/preview-server-plugin/plugin.ts: serverOutputDir = resolve(server.config.root, getServerOutputDirectory(server.config)) before the server entry path is built. The prerender request no longer resolves dist/server against the cwd.
- src/vite/prerender.ts (outputDir) and src/vite/post-server-build.ts (getClientOutputDirectory adapter): the client output directory is resolved against the environment root. TSS_CLIENT_OUTPUT_DIR is therefore absolute, and the sitemap and prerender writes in src/prerender.ts use it.
The issue's suggested diff and the implemented changes match. The PR adds an automated test in packages/start-plugin-core/tests/prerender-vite.test.ts (per the change summary) that checks the SSR root passed to the preview server and the resolved client output directory. The author states the test fails on main and that the package unit, eslint, and type checks pass. I did not run the test suite or the reproducer. The test covers the prerender.ts path. It does not directly cover the preview-server-plugin or post-server-build changes, so that part rests on code reading. The router-generator tmpDir behavior, which the issue marks as separate, is not changed here.
Full details: Out of Scope Changes check
-
Explanation
All changed files relate to the
#8825fix:- src/vite/prerender.ts: root passed to vite.preview() and client outDir resolved against the root. Both are in the linked objectives.
- src/vite/preview-server-plugin/plugin.ts: server output directory resolved against server.config.root. Required by objective 2.
- src/vite/post-server-build.ts: client output directory resolved against builder.config.root. Required by objective 3.
- tests/prerender-vite.test.ts: regression test for the root handling (per the change summary). Supporting test code for the fix.
- .changeset/start-prerender-vite-root.md: patch changeset for a published package. Documentation-type change that supports the release of the fix.
The diff adds no unrelated refactoring and does not touch router-generator. The changes stay within the issue's requested scope. The remaining uncertainty concerns the test content, which I read only from the change summary.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 4 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Comment `@coderabbitai help` to get the list of available commands.-
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: aa7de8392213a4bdaa49c0048b2e4432464af20d
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR