Skip to content

[chat] Cap markdown input length to avoid a render-thread freeze#23008

Open
Anexus5919 wants to merge 2 commits into
mui:masterfrom
Anexus5919:fix/chat-markdown-linear-parse
Open

[chat] Cap markdown input length to avoid a render-thread freeze#23008
Anexus5919 wants to merge 2 commits into
mui:masterfrom
Anexus5919:fix/chat-markdown-linear-parse

Conversation

@Anexus5919

Copy link
Copy Markdown
Contributor

Closes #22821

A large/dense markdown message freezes the render thread because renderMarkdown feeds the text straight into markdown-to-jsx, whose inline parser is super-linear and runs synchronously during render, with no input bound. Message bodies are effectively unbounded and attacker-influenceable (LLM output, a compromised backend/proxy, prompt injection, or a long paste), so a single large message can block the tab ('**a**'.repeat(16000) ≈ 78 KB → ~2 s freeze, scaling quadratically).

This adds a defense-in-depth input-length cap in renderMarkdown and its streaming sibling: past MAX_MARKDOWN_LENGTH (50 KB) the text is rendered as plain text (no truncation — all content stays visible) instead of being parsed. Realistic prose stays well under the cap and is unaffected; only pathological/oversized input degrades to plain text.

This is Layer 1 (the safety backstop) of the layered plan discussed on the issue. It closes the single-render freeze with the smallest possible diff. The streaming-smoothness layers (per-block cap, block-level memoization, and startTransition during streaming) are a planned follow-up and can be folded in here or shipped separately, per the maintainer's preference.

Changelog

Bounded the Chat markdown renderer so a very large message body is rendered as plain text instead of freezing the render thread.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@code-infra-dashboard

code-infra-dashboard Bot commented Jun 29, 2026

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-23008--material-ui-x.netlify.app/
QR code for https://deploy-preview-23008--material-ui-x.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) 0B(0.00%)
@mui/x-charts 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)
@mui/x-charts-premium 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)
@mui/x-scheduler 0B(0.00%) 0B(0.00%)
@mui/x-scheduler-premium 0B(0.00%) 0B(0.00%)
@mui/x-chat 🔺+50B(+0.02%) 🔺+26B(+0.03%)
@mui/x-license 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@Anexus5919

Copy link
Copy Markdown
Contributor Author

@hasdfa Kindly have a review on this pr. Thanks!

@zannager zannager added the scope: chat Changes related to the AI chat. label Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: chat Changes related to the AI chat.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[chat] Large markdown message freezes the render thread (no input-length bound)

2 participants