Skip to content
Source
Sign inSign up
TanStack/router

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

Closedmixelburg(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/8831/headopened

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.
    1. 🦋 Changeset detected

      Latest commit: cb8197bfa56a28e6d613249ca759dc94380b4cde

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

      This PR includes changesets to release 5 packages
      NameType
      @tanstack/start-plugin-corePatch
      @tanstack/react-start-rscPatch
      @tanstack/react-startPatch
      @tanstack/solid-startPatch
      @tanstack/vue-startPatch

      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

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      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 nameStatusExplanationResolution
      Docstring CoverageWarningDocstring 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 nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main change: resolving prerender paths against Vite's configured root.
      Description checkPassedThe 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 checkPassedIssue #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 checkPassedThe 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.
    3. TkDodo closed this

Sign in to join this conversation.