[Start] vite build keeps every environment's server-fn compiler alive until the build ends (memory stacks across client → ssr → server)
Maintainer thường phản hồi trong vòng 1 ngày
@Gourav224 đang làm issue này rồi.
Từ ngày 23/10/2026.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- typescript, vite
- Lĩnh vực
- build-system, performance
Hướng nghiên cứu
Read packages/start-plugin-core/src/vite/start-compiler-plugin/plugin.ts, focusing on startCompilerPlugin, its compilers Map, and buildStart. Check the linked pull request and compare its proposed cleanup with the reported build behavior; done means finished build environments release their compiler without breaking production builds. The issue reports a large-app Vite build as the reproducer.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Which project does this relate to?
Start
Describe the bug
In a production vite build, startCompilerPlugin keeps one compiler per environment in the compilers Map (packages/start-plugin-core/src/vite/start-compiler-plugin/plugin.ts). In build mode an entry is only removed in buildStart of the same environment, so it is never removed during a normal build: the client environment's compiler stays reachable while ssr and the server/provider environment build, and the ssr compiler stays reachable while the server environment builds.
Each compiler holds:
moduleCache: per-module info whosebindingskeep Babel AST nodes (init: declarator.initinextractModuleInfoFromAst,@tanstack/router-utils);loadModule/resolveIdclosures over the transform hook'sthis. The comment inbuildStartalready notes this ("The compiler host closes over this hook context for load/resolve"). That context keeps the finished phase's plugin context, and through it its module graph, reachable.
So live heap only grows from one environment to the next. In a large app this is the difference between fitting and not fitting under --max-old-space-size (we hit "JavaScript heap out of memory" in CI at a 6 GB cap).
Suggested fix: also drop the compiler when its environment's build finishes:
buildEnd() {
if (this.environment.mode === 'build') {
compilers.delete(this.environment.name)
}
},
In build mode the compiler is only used from transform (hotUpdate, watchChange and the lookup-capture plugin are serve-only), and Rollup/Rolldown's buildEnd runs after the last transform and this.load, so nothing uses it afterwards. Happy to open a PR with this and a changeset if that helps.
Reproducer
The app where we measured this is private, so I can't share it. The retention follows directly from the source on main:
https://github.com/TanStack/router/blob/main/packages/start-plugin-core/src/vite/start-compiler-plugin/plugin.ts (the compilers Map and buildStart)
Any Start app with enough modules shows it with node --trace-gc node_modules/vite/bin/vite.js build: the heap after each full GC keeps rising from the client build into ssr and the server build. I'm glad to try a patch or a canary on our build and report back.
Complete minimal reproducer
https://github.com/TanStack/router/blob/main/packages/start-plugin-core/src/vite/start-compiler-plugin/plugin.ts (our app is private: see "Reproducer" at the end of the description)
Steps to Reproduce the Bug
- In a large TanStack Start app (ours: ~5,500 client modules, ~5,800 server modules), run
node --max-old-space-size=6144 --trace-gc node_modules/vite/bin/vite.js build. - Note the heap after each Mark-Compact at the end of each environment's build.
- Apply the
buildEnddeletion above tostart-compiler-plugin/plugin.jsand build again.
Measured (heap after full GC, MB; Linux x64, Node 24.14, 4 vCPU, same machine, back to back):
| build | end of client | end of ssr | end of server (nitro) | max live heap | peak heap | time |
|---|---|---|---|---|---|---|
| unpatched | 1,809 | 2,718 | 5,930 | 5,930 | 5,974 | 191 s |
| patched | 1,456 | 2,223 | 4,709 | 4,710 | 5,030 | 163 s |
patched, --max-old-space-size=5120 |
1,456 | 2,218 | 4,702 | 4,703 | 4,771 | 170 s (completes) |
About 1.2 GB less live heap (−21%). The unpatched build cannot complete under a 5 GB cap. Of the 973 files in .output, 972 were byte-identical between the unpatched and patched builds; the one that differed (server/index.mjs) embeds build timestamps.
Expected behavior
Once an environment's build is done, its server-fn compiler (module cache, AST nodes and the captured plugin context) is released, so peak memory is set by the largest single environment rather than the sum of all of them.
Screenshots or Videos
No response
Platform
- Router / Start Version: @tanstack/react-start 1.168.60, @tanstack/start-plugin-core 1.171.49 (same code in 1.171.55 and on main)
- OS: Linux x64
- Browser: n/a (build-time)
- Browser Version: n/a
- Bundler: vite (+ nitro 3.0.260603-beta)
- Bundler Version: 7.3.6
Additional context
Even with the fix, about 2.2 GB is still live when the server environment starts. A likely second holder, which I haven't measured: the import-protection plugin's per-environment transformResultCache, which is only cleared at that environment's buildStart, so the ssr cache also lives through the server build. It's related to #8614, which is about dev rather than build. Happy to measure that one too.
- Ngôn ngữ chính
- TypeScript
- Star
- 15.3k
- Fork
- 1.9k
- Merge trung bình
- 1 ngày 5 giờ
- Pull request đã merge (30 ngày)
- 46
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TanStack/router
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Masked navigation drops the first character of the hash each time (__tempLocation hash missing '#')Có thể đã có người làm @hassanabrar202 đã nhận 8 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
router-generator: lazy-load Prettier (costs ~300–450ms per build even when formatting is off)Có thể đã có người làm @Sheraff đã nhận 27 ngày trước. Đang mởpackage: router-generator performance
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
router-generator: sibling `physical()` subtrees in a virtual route config generate duplicate identifiersCó thể đã có người làm @Sheraff đã nhận 27 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
docs(router): clarify static title fallback in SPA modeCó thể đã có người làm @Rohan-Dedhia đã nhận 17 ngày trước. Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của TanStack/router
Issue tương tự
-
[BUG]: Shared links drop the configured basePath on GitHub PagesCó thể đã có người làm @anshulchikhale30-p đã nhận hôm nay. Đang mởbug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
StabilityNexus/IdentityTokens-EVM-Frontend#182 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add: GTrekkerĐang mởcheck:passed streams:add
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Koenkk/zigbee-herdsman-converters#13900 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: ui Bug Payload OSS
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
payloadcms/payload#19839 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
jeanibarz/knowledge-base-mcp-server#1291 ·
Maintainer thường phản hồi trong vòng 1 ngày