fix(start-plugin-core): release each environment's server-fn compiler after its build #8797
main fromrefs/pull/8797/head·opened 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
serverFnsByIdregistry lives outside the compiler. compilers.getis otherwise only used in dev paths (hotUpdate,watchChange, the serve-only lookup plugin).- The bundledDev client environment runs in
devmode, so its compiler is kept forwatchChange.
Testing#
- New regression test
tests/vite/start-compiler-plugin-build.test.ts. It drives the plugin'sbuildStart,transformandbuildEndhooks for a build environment, then asserts through aWeakRefand 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:typesandtest:eslintall 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
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Source mode: Auto
- Repository: TanStack/router
- Branch: main
- File: .coderabbit.yaml
- Commit: 6b9fe6d
- Layers: Repository YAML
- Review profile: CHILL
- Plan: Advanced
- Run ID:
382d97f3-6f86-4724-afd4-c60ace66e368
📥 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.mdpackages/start-plugin-core/src/vite/start-compiler-plugin/plugin.tspackages/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.mdIn build mode, buildEndremoves the current environment’s compiler fromcompilers. 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:
4 · 1-
Failed checks: 1 warningCheck name Status Explanation Resolution Docstring Coverage 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 checks: 4 passed-
Check name Status Explanation Title check The title clearly and concisely describes the main change: releasing each environment's server-function compiler after its build. Description check 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 Issue #8794requires deleting each build environment's server-function compiler after that environment finishes. The newbuildEndhook inperEnvServerFnPlugindeletescompilersby `this.environm…Out of Scope Changes check 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
#8794requires deleting each build environment's server-function compiler after that environment finishes. The newbuildEndhook inperEnvServerFnPlugindeletescompilersbythis.environment.namewhen the mode isbuild. The regression test runsbuildStart,transform, andbuildEnd, then verifies release of the hook context throughWeakRefand 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.
Comment `@coderabbitai help` to get the list of available commands.-
Gourav224(GitHub profile, opens in a new tab) linked this to fix #8794
Sign in to join this conversation.
🦋 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
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