Skip to content
Source
Sign inSign up
TanStack/router

fix(start-plugin-core): release each environment's server-fn compiler after its build #8797

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

In build mode, startCompilerPlugin only drops an environment's compiler in that same environment's buildStart. Earlier environments' compilers (a module cache full of Babel ASTs, plus closures over the plugin hook context) therefore stay alive while later environments build. On a large app that is about 1.2 GB.

Fix

Add a buildEnd hook to the per-environment server-fn plugin. When this.environment.mode === 'build', it deletes that environment's compiler, matching the existing buildStart condition. Nothing reads an environment's compiler after its build ends:

  • The shared serverFnsById registry lives outside the compiler.
  • compilers.get is otherwise only used in dev paths (hotUpdate, watchChange, the serve-only lookup plugin).
  • The bundledDev client environment runs in dev mode, so its compiler is kept for watchChange.

Testing

  • New regression test tests/vite/start-compiler-plugin-build.test.ts. It drives the plugin's buildStart, transform and buildEnd hooks for a build environment, then asserts through a WeakRef and forced GC that the hook context is released. It fails before the fix and passes after.
  • @tanstack/start-plugin-core: test:unit (873 passed), test:types and test:eslint all pass.

Fixes #8794

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved cleanup after builds so completed build contexts can be released instead of remaining in memory. This helps avoid retaining unnecessary build resources while preserving the existing build behavior.
    1. 🦋 Changeset detected

      Latest commit: 67db0dfd05c617c6cc0b8eb39b0cfe2bbfcc821f

      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. Review in Change Stack →

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      📥 Commits

      Reviewing files that changed from the base of the PR and between 6b9fe6d29552270836c511bc9b343d73541f4424 and 67db0dfd05c617c6cc0b8eb39b0cfe2bbfcc821f.

      📒 Files selected for processing: 3
      • .changeset/release-start-compiler-after-build.md
      • packages/start-plugin-core/src/vite/start-compiler-plugin/plugin.ts
      • packages/start-plugin-core/tests/vite/start-compiler-plugin-build.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

      In build mode, the plugin now removes the current environment’s server-function compiler when the build ends. A new test checks whether the build context becomes unreachable, and a changeset declares a patch release.

      Changes: Server-function compiler build cleanup

      Layer / File(s)Summary
      Build-end compiler cleanup and validation
      packages/start-plugin-core/src/vite/start-compiler-plugin/plugin.ts, packages/start-plugin-core/tests/vite/start-compiler-plugin-build.test.ts, .changeset/release-start-compiler-after-build.md
      In build mode, buildEnd removes the current environment’s compiler from compilers. The test runs the build hooks and checks whether the associated context becomes unreachable after garbage collection. The changeset declares a patch release for @tanstack/start-plugin-core.

      Priority: ➖ Normal

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

      Change: Bug fix · Severity of issue fixed: Medium

      Merge Risk: ⚪ Minimal · up to 67db0

      No concrete merge-blocking risk was identified in the reviewed changes.

      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. Analyzed 4 functions across 2 files. (1 skipped: 1 …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: releasing each environment's server-function compiler after its build.
      Description checkPassedThe description clearly explains the problem, fix, implementation rationale, regression test, test results, and linked issue. It does not include the template's checklist or release-impact sections, b…
      Linked Issues checkPassedIssue #8794 requires deleting each build environment's server-function compiler after that environment finishes. The new buildEnd hook in perEnvServerFnPlugin deletes compilers by `this.environm…
      Out of Scope Changes checkPassedThe changes stay within issue #8794. The implementation releases the compiler, the test verifies the memory-release behavior, and the changeset records the package patch release. No unrelated source o…
      Full details: Description check

      Explanation

      The description clearly explains the problem, fix, implementation rationale, regression test, test results, and linked issue. It does not include the template's checklist or release-impact sections, but the required change and validation details are present.

      Full details: Linked Issues check

      Explanation

      Issue #8794 requires deleting each build environment's server-function compiler after that environment finishes. The new buildEnd hook in perEnvServerFnPlugin deletes compilers by this.environment.name when the mode is build. The regression test runs buildStart, transform, and buildEnd, then verifies release of the hook context through WeakRef and GC. The patch release changeset documents the fix.

      Full details: Out of Scope Changes check

      Explanation

      The changes stay within issue #8794. The implementation releases the compiler, the test verifies the memory-release behavior, and the changeset records the package patch release. No unrelated source or test changes are present in the reviewed diff.

      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 4 functions across 2 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.

Sign in to join this conversation.