Repository navigation
fix(markdown): cap rendered size of large Markdown previews to stop renderer freezes - #23634
Conversation
…rride The Open Preview tab rendered any file synchronously through react-markdown with no size check, and 'Open anyway' removed the rich-editor cap entirely. A 2 MB file blocked the renderer 7.8 s at 2.3 GB (5 MB: 38 s, 4 GB), matching scan29 crash reports where users killed a frozen Orca after opening a large .md. - Preview tab: over 600 KB shows a 'Render anyway' gate instead of rendering. - Both overrides stop at a 1 MiB hard cap; above it no render is offered.
…te copy The single-file diff Preview toggle sent the whole modified side to MarkdownPreview with only the 6 MB large-diff limit, so a multi-MB .md diff still froze the renderer. Wrap it in MarkdownPreviewSizeGate keyed by the diff tab id, and add the gate's strings to all locale catalogs.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (5)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughMarkdown rendering now uses a shared UTF-8 size check with a 1 MiB override limit. Rich mode, Markdown previews, and diff previews apply size limits and show override actions where allowed. PDF export eligibility checks the selected preview content against the active limit. Tests cover byte counting, override boundaries, and preview rendering. Locale entries provide preview and diff size-limit messages. Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to Large Markdown files can still freeze the app when opened in Edit-tab Preview, even above the 1 MiB cap. Gate that path and its PDF eligibility before merging. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The main Markdown rendering paths now limit large documents, including when a user chooses to render anyway. No new security weakness was established, though the review does not cover every rendering path or every costly document shape. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 10 files. (5 skipped: 5 unsupported.) Full details: Description checkExplanation The description is detailed and covers the change, motivation, testing, visual proof, risks, and checklist. However, it does not provide the required actual linked issue; it states that no GitHub issue exists and only lists crash-report links. Resolution Add an actual linked issue using the required
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Gate the edit-tab Preview mode before rendering. · EditorMarkdownFileSurface.tsx:151-153
src/renderer/src/components/editor/EditorMarkdownFileSurface.tsx:151-153
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy liftGate the edit-tab Preview mode before rendering.
When a user selects Preview on a Markdown edit tab, this branch mounts
MarkdownPreviewwithout a size check.getEditorPanelRenderModelskips rich-size classification in Preview mode, so a document above 1 MiB can still reach the whole-document renderer. Wrap this preview inMarkdownPreviewSizeGateusingactiveFile.idandcurrentContent. Apply the same size decision to edit-tab PDF export eligibility, which currently accepts a non-source render mode without checking its content size.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: f89d5fa2-75de-45e4-9721-c5ac7b2c919d
📒 Files selected for processing (16)
src/renderer/src/components/editor/EditorContent.markdown-classification.test.tsxsrc/renderer/src/components/editor/EditorContent.tsxsrc/renderer/src/components/editor/EditorDiffFileSurface.tsxsrc/renderer/src/components/editor/EditorMarkdownFileSurface.tsxsrc/renderer/src/components/editor/MarkdownPreviewSizeGate.tsxsrc/renderer/src/components/editor/editor-panel-render-model.tssrc/renderer/src/components/editor/large-markdown-render-freeze.test.tsxsrc/renderer/src/components/editor/markdown-rich-mode.tssrc/renderer/src/components/editor/markdown-rich-size-limit.test.tssrc/renderer/src/components/editor/markdown-rich-size-limit.tssrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/fr.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.json
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
There was a problem hiding this comment.
ℹ️ No blocking issues — the size gate covers the reachable render paths. One coverage note and a small copy nitpick below.
Reviewed changes
Reviewed the complete 16-file diff at 8821b05.
markdown-rich-size-limit.ts— extractedexceedsUtf8ByteLimit, added the 1 MiBMARKDOWN_RENDER_OVERRIDE_MAX_SIZE_BYTEShard cap andcanRenderMarkdownAtSize; reuses one probe buffer for both limits.MarkdownPreviewSizeGate.tsx— new wrapper that shows a notice plus "Render anyway" over the 600 KB soft limit, and no button over the hard cap.EditorContent.tsx/EditorDiffFileSurface.tsx— gate the preview tab and the diff-tab preview.editor-panel-render-model.ts— gate the preview tab's PDF export with the same size decision.markdown-rich-mode.ts/EditorMarkdownFileSurface.tsx— rich eligibility respects the hard cap even when overridden; "Open anyway" is hidden above it.- i18n —
editor.markdownPreview.*added to en/es/fr/ja/ko/zh. - Tests — new
large-markdown-render-freeze.test.tsxplus extended size-limit cases.
ℹ️ The diff-preview gate wraps a branch the UI cannot currently enter
I traced every producer of markdownViewMode and the diff/edit preview mode is unreachable: getMarkdownViewModes returns only ['source', 'rich'], and getEditorPanelRenderModel drops any stored value not in that list. So the mdViewMode === 'preview' branch in EditorDiffFileSurface (and the renderMode === 'preview' branch in EditorMarkdownFileSurface, whose <MarkdownPreview> is still ungated) is dead code today. The reachable freeze paths (preview tab, rich-editor override, PDF export) are correctly gated, so the fix itself is effective; the new diff-path tests characterize an injected prop rather than a user-reachable state.
Technical details
# Diff-tab preview gate and its tests cover an unreachable state
## Affected sites
- `src/renderer/src/components/editor/EditorDiffFileSurface.tsx:107` — `mdViewMode === 'preview'` branch the new gate wraps
- `src/renderer/src/components/editor/EditorMarkdownFileSurface.tsx:140` — sibling `renderMode === 'preview'` branch, renders `<MarkdownPreview>` without the gate
- `src/renderer/src/components/editor/editor-panel-render-model.ts:103` — `mdViewMode` constrained by `markdownViewModes.includes(stored)`
- `src/renderer/src/components/editor/markdown-preview-controls.ts:9-14,40-69` — no `*_VIEW_MODES` list contains `'preview'`
- `src/renderer/src/components/editor/large-markdown-render-freeze.test.tsx:163` — test injects `mdViewMode: 'preview'` directly
## Required outcome
- No change is needed for the freeze fix: preview tab, rich override, and PDF export are gated.
- If the inline diff/edit preview is intended to ship, its producer must assign `markdownViewMode = 'preview'`; until then the branch and its tests exercise dead code.
## Open questions for the human
- Is the diff-tab inline "Preview" toggle still planned (should `MARKDOWN_DIFF_VIEW_MODES`/`MARKDOWN_EDIT_VIEW_MODES` gain `'preview'`)? The PR description reads as though it exists today, which is why the diff gate was added.DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| : translate( | ||
| 'editor.markdownPreview.tooLarge', | ||
| 'File is larger than the {{limit}} preview limit. Open the file to view its source.', | ||
| { limit: formatBytes(RICH_MARKDOWN_MAX_SIZE_BYTES) } |
There was a problem hiding this comment.
The notice always cites the 600 KB soft limit, including files above the 1 MiB hard cap where no "Render anyway" button is offered. For those files rendering is not possible at all, so the wording (and the absent button) can read as a bug rather than a ceiling. Consider a distinct hard-cap string, or wording that says the file is too large to preview.
# Conflicts: # src/renderer/src/i18n/locales/es.json

Description
Opening a very large Markdown file could freeze Orca (and the user's whole PC) for tens of seconds and push the window's memory past 1-4 GB, until the user force-quit the app.
Before: The "Open Preview" tab and the Preview toggle on a Markdown diff tab rendered the whole file at once, whatever its size. In rich mode, "Open anyway" removed the existing 600 KB cap entirely.
After: Every path that renders a whole Markdown document at once now has a size check:
Mechanism:
markdown-rich-size-limit.tsaddscanRenderMarkdownAtSize, a fast UTF-8 byte-size check with a hard 1 MiB cap, next to the existing 600 KB soft limit.MarkdownPreviewSizeGatecomponent wrapsMarkdownPreviewinEditorContent.tsx(the preview tab) and inEditorDiffFileSurface.tsx(the modified side of a diff).getMarkdownRichModeEligibilityDecisionnow respects the hard cap even when the override is set.Why
The Markdown renderer (react-markdown with the gfm, math, raw-HTML, slug, highlight and KaTeX plugins) builds the whole document in one synchronous main-thread task. It is not chunked or virtualized, so cost grows with file size and there is nothing to yield to. Adding a size gate is the smallest change that removes the freeze. It matches the existing rich-mode fallback, so users see a familiar pattern.
Alternatives considered:
Linked Issue
No GitHub issue. Linked crash reports are listed below.
Fix evidence
1. Real-app repro on the released Electron. A hidden Electron 43.7.0 probe (same Electron as v1.4.215;
show:false) mounted the productionMarkdownPreviewBody.tsxand recorded long tasks, DOM nodes and working set:The V8 heap stays small (159 and 391 MB), so almost all of the memory is in Blink and the DOM. The crash telemetry has the same shape: renderer private memory 498 -> 1531 MB, Blink 32 -> 427 MB, V8 about 105 MB, main-thread gaps of 68-88 s between memory samples, and then a user kill.
2. Regression tests. Repro command:
Tests in
large-markdown-render-freeze.test.tsx:"Open anyway" still reaches the rich editor below the hard cap"Open anyway" cannot push a document past the hard cap into the rich editorpreview tab renders small documents directlypreview tab gates documents over the preview limit behind "Render anyway"preview tab never renders documents over the hard capdiff preview toggle gates the modified side over the preview limitdiff preview toggle never renders a modified side over the hard capBefore the fix, with
EditorContent.tsxandmarkdown-rich-mode.tsreverted tomain: 3 of the first 5 cases fail. WithEditorDiffFileSurface.tsxreverted:× diff preview toggle gates the modified side over the preview limitand× diff preview toggle never renders a modified side over the hard capfail (Tests 2 failed | 5 passed).After the fix:
Test Files 2 passed (2) / Tests 14 passed (14).3. Wider checks.
pnpm test src/renderer/src/components/editor: 257 files, 1823 passed, 3 skipped.pnpm tc: exits 0.oxlint: clean.pnpm run check:code-quality:changed: 0 findings.ELI5
Orca used to try to paint a whole huge Markdown file onto the screen in one go. For a 5 MB file that is over a million pieces, and while it paints, nothing else can happen: the app freezes for up to 38 seconds and eats 4 GB of memory.
Now Orca checks the file's size first:
Trade-offs
Adversarial review
It took 2 loops to come back clean. Each loop was a fresh reviewer.
MarkdownPreviewSizeGatekeyed by the diff tab id, with diff-specific wording, and 2 tests were added.Linked crash reports
Visual Proof
N/A for screenshots. This is a size gate that shows a text notice in place of the rendered preview. The behavior is covered by the component tests above.
Testing
This is renderer-only, content-string logic, with no platform, SSH or folder-workspace specific behavior.
Agent skill upstream boundary
Checklist
N/Awith reasonAdditional merge-risk verification (2026-10-02)
Integrated current main and resolved the Spanish catalog conflict by retaining every current-main entry and adding the three Markdown preview translations. On this integrated head, 26 regression tests passed, renderer typecheck passed, and the changed-code quality gate passed with zero findings. Existing unrelated untracked reproduction artifacts were excluded from that gate. The recorded hidden Electron reproduction establishes the huge-document freeze; the second field report lacks evidence that a Markdown file was open. The 600 KiB default / 1 MiB absolute cap intentionally leaves huge files in plain text.