Skip to content

fix(build): merge React vendors into one chunk to fix white screen - #3938

Merged
tcp404 merged 1 commit into
mainfrom
boii/fix/vendor-chunk-cycle
Aug 9, 2026
Merged

fix(build): merge React vendors into one chunk to fix white screen#3938
tcp404 merged 1 commit into
mainfrom
boii/fix/vendor-chunk-cycle

Conversation

@tcp404

@tcp404 tcp404 commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

Description

Fixes a full white screen in every packaged / statically-served build (desktop dmg + electron-vite preview, the WebUI toggle, and aionui-web).

Root cause (build-level, on main). packages/desktop/electron.vite.config.ts manualChunks split React and its tightly-coupled vendors into separate chunks (vendor-react, vendor-arco, vendor-highlight, vendor-markdown, vendor-editor), producing circular ESM chunk imports:

vendor-editor -> vendor-highlight -> vendor-arco -> vendor-react -> vendor-editor
vendor-highlight -> vendor-markdown -> vendor-highlight

With a chunk cycle, ESM evaluation order left React's exports uninitialized when vendor-arco's top level ran React.createContext, throwing:

Uncaught TypeError: Cannot read properties of undefined (reading 'createContext')
  at vendor-arco-*.js:1

#root stayed empty → 100% white screen. Dev (bun start) is immune because Vite serves unbundled ESM (no manualChunks). All three production consumers serve the same out/renderer, so all three white-screen.

Fix. Co-locate react / react-dom / @arco-design / markdown / highlight / editor / katex into a single vendor chunk, removing the cross-chunk cycle. A single vendor chunk loads from disk (file://) so the extra granularity bought nothing but the cycle.

Type of Change

  • fix — Bug fix (non-breaking change which fixes an issue)

Atomic PR Checklist (Rule 1)

  • This PR contains exactly one bug fix
  • The PR title follows Conventional Commit format

Local Checks (Rule 3)

  • bun run format — passes (via just push)
  • bun run lint — 0 errors (via just push)
  • bunx tsc --noEmit — passes (via just push)
  • bunx vitest run — 3964 passed / 5 skipped (via just push)
  • i18n validated (via just push)

Runtime Verification

  • Verified on macOS
  • Verified on Windows
  • Verified on Linux
  • I have performed a self-review of my own code

Verified on macOS:

  • bun run packagezero circular-chunk warnings (was 2); single merged vendor chunk.
  • Production build (electron-vite preview, file://out/renderer) at 390px: #root non-empty, React mounts, no longer white (was rootLen=0 / 100% white / createContext crash).
  • WebUI (bun run webui) at 390px: renders, React mounts.
  • File preview at 390px in a project conversation: text / image / pdf / office all render.

Additional Context

Chunk-boundary / build-config only; no runtime/source behavior change. Unblocks the mobile WebUI file-preview goal (that path serves the same out/renderer).

- Production manualChunks split react/@arco/markdown/highlight/editor
  into separate vendor chunks, forming circular ESM chunk imports
  (vendor-editor -> vendor-highlight -> vendor-arco -> vendor-react ->
  vendor-editor). Evaluation order left React's exports uninitialized
  when vendor-arco ran React.createContext, throwing
  "Cannot read properties of undefined (reading 'createContext')" and
  leaving #root empty — a full white screen in every packaged/served
  build (desktop dmg, WebUI switch, aionui-web all serve out/renderer).
- Co-locate react/react-dom/@arco-design/markdown/highlight/editor/katex
  into a single `vendor` chunk, removing the cross-chunk cycle. A single
  vendor chunk loads from disk (file://) so the extra granularity added
  nothing but the cycle.
- Verified: bun run package emits zero circular-chunk warnings;
  production build + WebUI at 390px no longer white; text/image/pdf/office
  previews all render.
@tcp404
tcp404 requested a review from IceyLiu as a code owner August 9, 2026 05:01
@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@tcp404
tcp404 merged commit 019400b into main Aug 9, 2026
15 checks passed
@tcp404
tcp404 deleted the boii/fix/vendor-chunk-cycle branch August 9, 2026 06:33
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.

1 participant