Skip to content
Source
Sign inSign up
TanStack/router

Forward Vite config loader to prerender preview server #8615

OpenCreedTech(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/8615/headopened

Summary

 startPreviewServer(viteConfig)
   vite.preview({
     configFile: viteConfig.configFile,
+    configLoader: viteConfig.inlineConfig.configLoader,
   })

Forward the loader used by the original Vite build to the preview server created for static prerendering. Add a dedicated React Start e2e app whose config imports through a custom Node condition; its build exercises the failure path. Fixes #7593. Thanks to @sebastienbarre for the reproducer and proposed fix.

Evidence

  • Before: The fixture's client and server builds completed, then prerendering failed with Failed to start the Vite preview server for prerendering and ERR_PACKAGE_IMPORT_NOT_DEFINED when Vite reloaded the config through its default bundler.
  • After: The fixture builds, serves its preview, and its Playwright project confirms the prerendered index.html contains the expected page content. The regression test checks the generated page without launching a browser.
  • @tanstack/start-plugin-core: 580 unit tests passed (1 existing expected failure), type checks across the repository's TypeScript matrix passed, ESLint passed, and the package build check passed.
  • The dedicated e2e project passed (1 passed).
  • pnpm format and git diff --check passed.

Merge Danger

Door: Two-way

Blast Radius: Vite preview startup during TanStack Start static prerender builds. When no loader was specified, Vite continues to use its default.

Summary by CodeRabbit

  • Bug Fixes
    • Static prerendering now uses the same Vite config loader as the build, allowing pages that rely on native config loading to prerender successfully.
    1. changeset-bot[bot](GitHub profile, opens in a new tab)commented

      🦋 Changeset detected

      Latest commit: 9c695290753bcdc71e71bb827e81baf2d7f2bce2

      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 →

      Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

      Important

      Review skipped

      Review was skipped as selected files did not have any reviewable changes.

      ⛔ Files ignored due to path filters (1)
      • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
      ⚙️ Run configuration
      • Configuration used: Repository: TanStack/router/.coderabbit.yaml
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: 3b38caf5-b368-4433-aa04-8e2b03a6729d
      📥 Commits

      Reviewing files that changed from the base of the PR and between 8f0825a036afba2c81ff2cf98820f3f1dfcb2d53 and 9c695290753bcdc71e71bb827e81baf2d7f2bce2.

      ⛔ Files ignored due to path filters (1)
      • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Repository: TanStack/router/.coderabbit.yaml
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: a03abde0-43f8-4873-ac9a-eacf7ec3babf
      📥 Commits

      Reviewing files that changed from the base of the PR and between efc2042c2d02a9780c3e7efe81f123d066a869eb and 8f0825a036afba2c81ff2cf98820f3f1dfcb2d53.

      ⛔ Files ignored due to path filters (1)
      • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
      📒 Files selected for processing (16)
      • .changeset/curvy-hats-go.md
      • e2e/react-start/config-loader-prerender/.gitignore
      • e2e/react-start/config-loader-prerender/.prettierignore
      • e2e/react-start/config-loader-prerender/README.md
      • e2e/react-start/config-loader-prerender/package.json
      • e2e/react-start/config-loader-prerender/playwright.config.ts
      • e2e/react-start/config-loader-prerender/src/routeTree.gen.ts
      • e2e/react-start/config-loader-prerender/src/router.tsx
      • e2e/react-start/config-loader-prerender/src/routes/__root.tsx
      • e2e/react-start/config-loader-prerender/src/routes/index.tsx
      • e2e/react-start/config-loader-prerender/support.ts
      • e2e/react-start/config-loader-prerender/tests/app.spec.ts
      • e2e/react-start/config-loader-prerender/tsconfig.json
      • e2e/react-start/config-loader-prerender/vite.config.ts
      • packages/start-plugin-core/src/vite/prerender.ts
      • packages/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

      Walkthrough

      Static prerendering now forwards the resolved Vite config loader to the preview server. A new React Start end-to-end fixture builds with the native loader and checks the prerendered client HTML.

      Changes

      Static prerendering with native config loader

      Layer / File(s)Summary
      Forward the loader and update unit fixtures
      packages/start-plugin-core/src/vite/prerender.ts, packages/start-plugin-core/tests/prerender-vite.test.ts, .changeset/curvy-hats-go.md
      startPreviewServer passes viteConfig.inlineConfig.configLoader to vite.preview. The SSR test fixtures include inlineConfig. A patch changeset records the forwarding change.
      Add native-loader prerender E2E coverage
      e2e/react-start/config-loader-prerender/*, e2e/react-start/config-loader-prerender/src/*, e2e/react-start/config-loader-prerender/src/routes/*, e2e/react-start/config-loader-prerender/tests/*
      The fixture configures native-loader builds and preview, enables prerendering, and checks that the built client HTML contains the expected page text.

      Priority: ➖ Normal

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

      Change: Bug fix · Severity of issue fixed: Medium

      Merge Risk: ⚪ Minimal · up to 8f082

      The change appears ready to merge after normal checks; no actionable merge-blocking risk was identified.

      Security Architecture Review

      Security architecture risk: 🔵 Low · up to 8f082

      Preview now uses the configuration loader already selected for the build. No introduced security finding was established, and existing request restrictions remain intact. Compatibility across supported Vite versions and uncommon failure or interruption paths remain incompletely verified.

      Retained concerns No architecture-level concerns identified.

      Security review details

      Security Blast Radius

      • inferred — The bounded exposure is the project build process and its prerender preview server. Successful native-loader startup exercises existing server behavior, but the reviewed change does not establish a new loader-selection authority for an unauthenticated caller. Actual preview network exposure still depends on the project's loaded configuration.

      Trust Boundaries and Controls

      • observed — Existing controls bind requests to the actual preview origin, use manual redirects, reject redirects to another origin or credential-bearing URLs, and constrain output paths to the client output directory. These controls are unchanged by loader forwarding.

      Resilience and Maintainability Implications

      • observed — Rendering completion and failures inside the rendering try block close preview in finally. Origin discovery and initial page validation occur before that cleanup protection, so exceptions there can bypass it. This containment gap exists in both base and head; whether Vite returns a server without a local resolved URL remains unverified.
      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 10 files. (6 skipped: 6…Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Title check✅ PassedThe title clearly and concisely identifies the main change: forwarding the Vite config loader to the prerender preview server.
      Description check✅ PassedThe description explains the change, motivation, regression test, validation results, and blast radius. It does not include the template’s checklist or a separate Release Impact section, but the chang…
      Linked Issues check✅ PassedIssue [#7593] requires the prerender preview to reuse the original Vite config loader. startPreviewServer now passes viteConfig.inlineConfig.configLoader to vite.preview. The new React Start fix…
      Out of Scope Changes check✅ PassedThe changes support [#7593]: the fixture, Playwright check, and package changeset cover or document the regression; the prerender test fixture updates accommodate inlineConfig. The summary shows no …
      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. Analyzed 5 functions across 10 files. (6 skipped: 6 unsupported.)

      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR
      • Autopilot · 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. Hi @Sheraff, could you take a look at this? The prerender preview now uses the same Vite config loader, and the React Start E2E fixture covers the regression.

    4. Just a friendly ping to check if this will be merged at some point? Thank you very much

    5. so sorry, i missed the notification

      Thanks for the ping @sebastienbarre. This is still open and awaiting maintainer review. The PR forwards the build's config loader to the prerender preview server and includes a regression fixture. @Sheraff, could you take a look when you have time?

Sign in to join this conversation.