fix(desktop): reload Vite when workspace exports change - #4643
Conversation
Workspace manifests live outside the renderer watch root, and ordinary file invalidation leaves Vite's native package resolver cache stale. Register those manifests as configuration dependencies so Vite owns watching and restarting. Keep package exports authoritative and retain the existing workspace build flow. Generated-by: Codex
M4n5ter
left a comment
There was a problem hiding this comment.
Approved from the code-review perspective.
The Vite lifecycle and regression behavior are sound. The current required test check fails because check-renderer-architecture.mjs still pins the Vite plugin array to exactly four entries and the previous indices. This PR inserts workspacePackagesPlugin, so that checker deterministically reports “Vite must build src/renderer/index.html into dist-renderer without an input override.” Please update the checker and its canonical fixture to recognize workspacePackagesPlugin(REPO_ROOT), while keeping rendererEntryContractPlugin as the final guard. Once that contract mismatch is fixed and CI passes, this change is acceptable.
中文
从代码审查角度批准。
Vite 生命周期和回归行为本身没有问题。目前必需的 test 检查失败,是因为 check-renderer-architecture.mjs 仍把 Vite plugin 数组固定为 4 项并使用旧索引;本 PR 插入 workspacePackagesPlugin 后,checker 会稳定报出“Vite must build src/renderer/index.html into dist-renderer without an input override”。请同步更新 checker 及其 canonical fixture,明确接受 workspacePackagesPlugin(REPO_ROOT),并继续保持 rendererEntryContractPlugin 为最后一道 guard。修复该 contract 不一致且 CI 通过后,此变更即可接受。
…ract The renderer entry guard pins Vite plugin identity, arguments, and order. Include the workspace export invalidation plugin in that contract while preserving the entry and output restrictions. Update the existing valid-entry fixture to exercise the production plugin list. Generated-by: Codex
Summary
When a running Desktop dev server loads an updated renderer import after a workspace adds a package export, Vite can keep resolving against the old manifest and show
"./workhub-session-resolver" is not exported under the conditions [...]. The export introduced in #4439 is present in main; the stale resolver is the failing boundary.Register the root manifest and its declared workspace manifests as Vite configuration dependencies. Vite then watches these files outside the renderer root and uses its existing server restart path to replace the native resolver cache. Ordinary file watching alone does not clear that cache.
The addition is a dev-only Vite plugin for missing invalidation metadata. Package exports remain the resolution authority; there is no separate cache or restart controller to maintain. Workspace build outputs still come from the existing build flow. This does not add library, main-process, or preload hot rebuilding.
The renderer architecture contract also pins the new plugin import, repository-root argument, and position alongside the existing entry guards. Its valid-entry fixture uses the same plugin list.
Verification
test:dist.@maka/core.148f8eb297c86aa3045c75e87e19cacd4967c2dc, including 71 existing architecture tests. The updated valid-entry fixture failed before the checker was updated.application/contracts/workhub-request-intent.tswith HTTP 200 and resolved the new core export.npm run format,npm run lint, focused plugin TypeScript check, Windows test inventory, andgit diff --checkpassed.AI use
Tool(s) and scope: Codex investigated the resolver cache, implemented the Vite integration, and wrote and ran the regression test.
Checklist
Does this PR entail a change in behavior?