Skip to content

perf(editor): add lazy viewport loading for MonacoEditorCore and ReadOnlyCodeBlock - #3804

Open
Raing5Days wants to merge 1 commit into
GCWing:mainfrom
Raing5Days:perf/monaco-pool-opt
Open

Raing5Days wants to merge 1 commit into
GCWing:mainfrom
Raing5Days:perf/monaco-pool-opt

Conversation

@Raing5Days

Copy link
Copy Markdown
Contributor

Summary of Changes

  • Viewport intersection lazy loading: Added \lazy\ prop support to \MonacoEditorCore\ and enabled it by default in \ReadOnlyCodeBlock.
  • Eliminate offscreen editor instantiation: When code blocks are rendered outside the readable viewport (e.g. in conversation history, collapsed tools, or documentation previews), creation of the heavy Monaco editor instance (\monaco.editor.create), DOM nodes, and event listeners is deferred until the block intersects within 200px of the viewport.
  • Graceful SSR/environment fallback: Automatically falls back to immediate instantiation when \IntersectionObserver\ is unavailable.

Verification

  • Unit tests:
    • Added \ReadOnlyCodeBlock.test.tsx\ covering deferred instantiation under \lazy={true}\ until intersection and immediate instantiation when \lazy={false}.
    • \CodeEditor.test.tsx: 15/15 tests passed.
    • Regression verified with full editor test suite.

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