Skip to content

fix(start-plugin-core): resolve prerender paths against the Vite root - #8831

Open
mixelburg wants to merge 1 commit into
TanStack:mainfrom
mixelburg:fix/prerender-resolve-against-vite-root
Open

mixelburg wants to merge 1 commit into
TanStack:mainfrom
mixelburg:fix/prerender-resolve-against-vite-root

Conversation

@mixelburg

@mixelburg mixelburg commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #8824. prerenderWithVite resolved its paths against process.cwd() instead of Vite's resolved root, so vite build <dir> and createBuilder({ root }) failed to start the preview server or wrote index.html, pages.json and sitemap.xml outside the project whenever root ≠ cwd. Now root is passed to vite.preview(), the preview server imports its entry via resolve(server.config.root, …), and post-server-build returns the client output directory resolved against the builder root; TSS_CLIENT_OUTPUT_DIR follows suit.

Verified with the reporter's reproducer built from the parent directory: before, exit 1 (Could not resolve entry for router entry: router in <cwd>/app); after, exit 0, / prerendered into <project>/dist/client, nothing written to the working directory. vitest run in start-plugin-core (49 files / 873 tests), tsc --noEmit, eslint and prettier are clean, and tests/prerender-vite.test.ts has a regression test for the resolved root and client output directory.

Summary by CodeRabbit

  • Bug Fixes
    • Prerendering and preview server paths now resolve relative to the configured project root, even when it differs from the current working directory. This helps preview servers start reliably and keeps generated files within the project.

prerenderWithVite resolved the client output directory, the preview server and the server build entry against process.cwd(), so `vite build <dir>` and `createBuilder({ root })` failed to start the preview server or wrote index.html, pages.json and sitemap.xml outside the project whenever the Vite root was not the working directory.

Resolve all three against the resolved config root and pass root to vite.preview().
@changeset-bot

changeset-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cb8197b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@tanstack/start-plugin-core Patch
@tanstack/react-start-rsc Patch
@tanstack/react-start Patch
@tanstack/solid-start Patch
@tanstack/vue-start Patch

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

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

Prerender path handling now uses Vite’s configured root for the preview server and client and server output directories. A test verifies the preview root and resolved client output path.

Changes: Prerender path resolution

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/quiet-prerender-root.md
The prerender setup passes the client environment’s root to Vite preview and resolves client and server output directories against their configured roots. The test checks the preview root and resolved client output path. The changeset records the patch.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

  • Issue 8825 describes root-relative prerender failures for vite build <dir> and createBuilder({ root }), which this change addresses.

Possibly related PRs

Suggested labels: package: start-plugin-core

Merge Risk: Minimal · up to cb819

No concrete merge-blocking risk remains; the root-aware path changes align with Vite’s resolution behavior.

Pre-merge checks: Passed 4 · Failed 1

Failed 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%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: resolving prerender paths against Vite's configured root.
Description check Passed The description explains the change, motivation, affected behavior, reproduction results, tests, and regression coverage. It does not reproduce the template headings or checklist, but the required tec…
Linked Issues check Passed Issue #8824 is directly linked and active. The reviewed code passes serverEnv.config.root to vite.preview(), resolves the client output directory against clientEnv.config.root, and resolves the …
Out of Scope Changes check Passed The changes are limited to root-aware prerender path handling, the related server and client output paths, a regression test, and a package changeset. These changes directly support issue #8824. No un…
Full details: Description check

Explanation

The description explains the change, motivation, affected behavior, reproduction results, tests, and regression coverage. It does not reproduce the template headings or checklist, but the required technical information is mostly complete.

Full details: Linked Issues check

Explanation

Issue #8824 is directly linked and active. The reviewed code passes serverEnv.config.root to vite.preview(), resolves the client output directory against clientEnv.config.root, and resolves the server output directory against server.config.root before importing the server entry. The regression test checks the preview root and TSS_CLIENT_OUTPUT_DIR. The supplied validation reports successful builds from a parent directory with output under the project root. The issue’s separate router-generator tmpDir behavior is explicitly outside this PR’s required scope.

Full details: Out of Scope Changes check

Explanation

The changes are limited to root-aware prerender path handling, the related server and client output paths, a regression test, and a package changeset. These changes directly support issue #8824. No unrelated implementation is shown.

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 with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 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.

❤️ Share

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

This branch has not been deployed

No deployments
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.

Prerender ignores Vite's root: vite build <dir> and createBuilder({ root }) fail from another folder

1 participant