Repository navigation
perf: split vendor chunks and load the editor on demand - #387
Open
sunxiaobin89 wants to merge 1 commit into
Open
sunxiaobin89 wants to merge 1 commit into
sunxiaobin89 wants to merge 1 commit into
Conversation
The production bundle was a single 3.45 MB entry chunk. The ineffective
import('@tauri-apps/api/window') in App.tsx was the only dynamic import
and split nothing, because the menu bar already imports that module
statically.
- vite: split xterm, charts, CodeMirror and the locale JSON into named
chunks. Only self-contained leaf packages are grouped: an earlier
catch-all vendor group created a sonner<->cmdk cycle across chunks and
the production app died with "t is not a function" before first paint.
- main.tsx: the detached file viewer loads FileViewerWindow lazily.
- terminal-tab-portals: lazy-load FileEditorView behind Suspense so the
~1.1 MB CodeMirror chunk only downloads when a file is opened.
- App.tsx: import getCurrentWindow statically instead of dynamically.
Result: entry 3.45 MB -> 1.61 MB, and the 1.11 MB editor chunk is no
longer preloaded. Verified with 2181 frontend tests, tsc, and a real
tauri build --debug: the main window renders, the SSH session connects,
and double-clicking a file opens the editor tab with its content.
sunxiaobin89
force-pushed
the
perf/code-splitting
branch
from
December 3, 2026 05:34
e9b2ffb to
6e7dd42
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
生产构建原本只有一个 3.45 MB 的入口 chunk,其中唯一的动态导入还是无效的。
@xterm、图表库(recharts/d3)、CodeMirror 和src/locales拆成命名 chunk。只对无环的叶子依赖分组。最初用 catch-all vendor 组 +maxSize的尝试把 sonner 和 cmdk 分到不同 chunk,导致生产应用在首屏前崩溃(Uncaught TypeError: t is not a function)。该问题通过把构建产物加载到浏览器中复现后,收紧了配置,直到模块图能正常初始化。import()FileViewerWindow。FileEditorView改为lazy()+Suspense,1.1 MB 的 CodeMirror chunk 只在首次打开文件时下载,而不是启动时。getCurrentWindow改为静态导入。菜单栏本来就静态导入了同一个模块,所以原来的动态导入产生INEFFECTIVE_DYNAMIC_IMPORT且没有拆分任何东西。结果:入口 3.45 MB → 1.61 MB;1.11 MB 的编辑器 chunk 已不再出现在预加载列表中。
测试计划
pnpm exec tsc --noEmit→ 通过pnpm test→ 2181 passed / 16 skipped(编辑器标签页测试覆盖了新的 Suspense 边界)pnpm build→ 成功;对构建产物做浏览器加载探测,无模块初始化错误pnpm tauri build --debug --bundles app后启动,SSH 连接 localhost → 主窗口正常渲染并连接;双击~/rshell-split-check.txt→ 编辑器标签页打开并显示文件内容,证明动态导入的 chunk 在 Tauri 资源协议下可正常加载说明
index(1.61 MB)和按需加载的vendor-editor(1.11 MB)仍高于 Vite 的 500 kB 建议值。要再降低入口体积,需要把更多常驻界面(设置、对话框)改为懒挂载,本 PR 有意不做。