Skip to content

fix(electron): resolve main output root from inside Rollup chunks - #1307

Merged
vastsa merged 2 commits into
vastsa:mainfrom
mingkun968:fix/main-module-chunks-blackscreen
Oct 2, 2026
Merged

vastsa merged 2 commits into
vastsa:mainfrom
mingkun968:fix/main-module-chunks-blackscreen

Conversation

@mingkun968

Copy link
Copy Markdown
Contributor

紧急修复:打开黑屏。

原因: Rollup 把 Main 拆成 out/main/index.js + out/main/chunks/,getModuleDirectory 返回 chunk 目录,导致 renderer/preload/plugin-host 路径深了一层,窗口加载到不存在的 index.html。

改动(最小,1 文件):

  • apps/desktop/electron/main/module-path.ts:剥掉尾部 chunks 段,回到 out/main。

验证:

  • pnpm --filter @pi-desktop/desktop typecheck 通过
  • node 直验:chunks 与入口均归一到 out/main,../renderer/index.html 正确
  • 未含 asktool-compact-preview.html 与 test 增量

Rollup emits Main as out/main/index.js plus shared chunks under
out/main/chunks/. getModuleDirectory returned the chunk directory,
so renderer/preload/plugin-host paths resolved one level too deep
and the window loaded a missing index.html (black screen).

@vastsa vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当前不建议合入。这个改动修复了可见的启动黑屏路径,但 PR 只改了 module-path.ts,没有提交能在旧实现上失败的回归测试,也没有按仓库要求更新对应的 E2E 启动场景文档。PR 描述中的临时 node 直验不能在后续改动时自动防止回归。

请补一个针对 getModuleDirectory() 的自动化回归用例,覆盖入口模块与 out/main/chunks/*.js 都解析到 out/main,并更新 docs/spec/06-delivery/04-e2e-test-plan.md 中的启动场景,明确覆盖 Main 共享 chunk 下的 renderer/preload 路径。然后在包含最新 origin/main 的候选上运行相关测试和 Electron 启动 E2E。

我确认 PR head 包含当前 origin/main,GitHub CI、PR base 检查均通过。此处隔离 worktree 的本地 typecheck 与 E2E 未能有效运行:pnpm 拒绝共享的 node_modules 根符号链接;直接 typecheck 使用了不完整/陈旧的 workspace dist,启动 E2E 也因 Desktop 未构建而退出。这些本地限制不影响 CI 结果,但当前也没有上述回归覆盖,因此先 request changes,不合入。

Add a regression test proving getModuleDirectory() resolves to
out/main from both the entry bundle and out/main/chunks/*.js, so
renderer/preload/plugin-host paths cannot drift one level deep
again. Document the shared-chunk layout in E2E-001.
@mingkun968

Copy link
Copy Markdown
Contributor Author

已按反馈补充(b043189e0):

  • 回归测试 apps/desktop/test/main-module-path.test.mjs:覆盖入口 out/main/index.js 与 out/main/chunks/*.js 都解析到 out/main,并断言 ../renderer/index.html 与 plugin-host-process.js 相对路径不变。已验证在旧实现上失败(chunk 目录返回 .../out/main/chunks)、新实现通过(node --test test/main-module-path.test.mjs pass)。
  • E2E-001 文档:docs/spec/06-delivery/04-e2e-test-plan.md 明确 Main 共享 chunk 下的 renderer/preload 路径约定,Status 标注新测试覆盖。
  • pr-base OK(含最新 origin/main)。CI 正在跑,请再看下是否可合入。

@vastsa
vastsa merged commit 82f94b4 into vastsa:main Oct 2, 2026
4 checks passed
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.

2 participants