Skip to content

perf(components): lazy-load Monaco editor and pdfjs viewer - #2991

Open
wibus-wee wants to merge 1 commit into
mainfrom
perf/lazy-monaco-pdf-viewers
Open

wibus-wee wants to merge 1 commit into
mainfrom
perf/lazy-monaco-pdf-viewers

Conversation

@wibus-wee

Copy link
Copy Markdown
Member

Why

session-detail chunk statically bundled Monaco (~3.7 MB decoded) and PDF.js. Every app session paid the download+parse cost even when no text/PDF file was ever opened. The office preview renderer already uses await import() — Monaco/pdfjs were the only heavy viewers still eager.

What

  • lazy-session-monaco-text-viewer.tsx — React.lazy + Suspense wrapper around SessionMonacoTextViewer; same props, spinner fallback while the 3.7 MB monaco chunk loads.
  • code-collab-monaco-model-provider.ts — monaco-free module extracted so URI build/parse helpers no longer pull monaco-editor into the boot chunk; buildCodeCollabMonacoUri callers in session-file-content-view now point here.
  • pdf-range-transport.ts — extracted so the PDF streaming transport can be used without statically importing pdfjs-dist.
  • session-file-binary-preview.tsx — SessionFilePdfPreview behind React.lazy.
  • mobile-project-file-browser.tsx — monaco viewer behind lazy boundary.
  • session-file-content-view.tsx, session-monaco-*.ts — imports rewired to lazy/monaco-free modules.
  • session-share-publisher.ts — zstd await import('@loro-dev/streams-crdt/zstd') (also part of the wasm-deferral line; harmless here).

Verification

  • apps/electron renderer build emits monaco as a separate 3.69 MB async chunk and pdfjs worker as separate lazy chunks — verified in build output.
  • tsc --noEmit clean in packages/shared and packages/components.
  • 110 related tests pass.

No behavior change — same props, same keys, same loading fallbacks; the spinner is the only new visible state while the monaco chunk fetches on first open.

Monaco (~3.7MB) and pdfjs were statically imported by the session file
viewer, so every app load paid for both even when the user never opened
a code file or a PDF. Follow the existing office-preview convention and
load them on demand.

- SessionMonacoTextViewer -> LazySessionMonacoTextViewer (React.lazy +
  Suspense, Spinner fallback) at both call sites in
  session-file-content-view and the two in mobile-project-file-browser.
- session-monaco-language-providers kept a top-level monaco import just
  for monaco.Uri. The code-collab URI scheme + fileId->provider registry
  moved to code-collab-monaco-model-provider.ts, which is monaco-free
  (hand-rolled URI build/parse, byte-identical to monaco.Uri output).
  The old module re-exports it and keeps monaco only for the language
  providers that run inside the editor chunk.
- SessionFilePdfPreview -> lazy() + Suspense, matching the office
  renderer pattern. pdf-file-preview's static pdfjs import became
  type-only; createLocalPdfRangeTransport dynamically imports the new
  pdf-range-transport module.

Electron renderer build emits session-monaco-text-viewer-*.js (3.69MB),
pdf-*.js (495kB) and session-file-pdf-preview-*.js (229kB) as async
chunks; the main entry no longer contains monaco/pdfjs code.

Model: magpie/orchestrator

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant