Skip to content

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

Open
Gourav224 wants to merge 1 commit into
TanStack:mainfrom
Gourav224:fix/release-server-fn-compiler-after-build
Open

Gourav224 wants to merge 1 commit into
TanStack:mainfrom
Gourav224:fix/release-server-fn-compiler-after-build

Conversation

@Gourav224

@Gourav224 Gourav224 commented Oct 23, 2026 •

Copy link
Copy Markdown

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.

… after its build

Fixes TanStack#8794

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Oct 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 67db0df

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 23, 2026 •

Copy link
Copy Markdown
Contributor

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 6b9fe6d and 67db0df.

📒 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 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. 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 name Status Explanation
Title check Passed The title clearly and concisely describes the main change: releasing each environment's server-function compiler after its build.
Description check Passed 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, b…
Linked Issues check Passed 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.environm…
Out of Scope Changes check Passed 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 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.

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.

[Start] vite build keeps every environment's server-fn compiler alive until the build ends (memory stacks across client → ssr → server)

1 participant