Skip to content

fix: message parser breaking workspace#40306

Draft
nazabucciarelli wants to merge 10 commits intodevelopfrom
fix/message-parser-max-length-prevention
Draft

fix: message parser breaking workspace#40306
nazabucciarelli wants to merge 10 commits intodevelopfrom
fix/message-parser-max-length-prevention

Conversation

@nazabucciarelli
Copy link
Copy Markdown
Contributor

@nazabucciarelli nazabucciarelli commented Apr 24, 2026

Proposed changes (including videos or screenshots)

Prevents the message parser from blocking the client on large messages.

Benchmarks show the parser has superlinear complexity on nested markdown tokens — at ~315KB it takes ~10s, freezing the workspace (you can see the results here). This PR adds a MESSAGE_PARSE_HARD_LIMIT of 20,000 characters: messages exceeding it are rendered as plain text instead of being parsed.

Changes:

  • Added useMaxMessageParseSize hook to centralize the limit logic
  • Updated useNormalizedMessage (room/thread messages) and useMessageBody (thread previews) to skip parsing when the limit is exceeded
  • Updated QuoteAttachment to apply the same limit for consistency
  • Added i18nDescription to Message_MaxAllowedSize setting to warn admins that values above the hard limit affect markdown rendering
  • Added unit tests

Issue(s)

SUP-1019

Steps to test or reproduce

Further comments

@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented Apr 24, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 24, 2026

🦋 Changeset detected

Latest commit: 43e6955

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 42 packages
Name Type
@rocket.chat/i18n Patch
@rocket.chat/meteor Patch
@rocket.chat/mock-providers Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/ui-client Patch
@rocket.chat/ui-voip Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/gazzodown Patch
@rocket.chat/livechat Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/queue-worker Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/ddp-client Patch
@rocket.chat/http-router Patch
@rocket.chat/model-typings Patch
@rocket.chat/models Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/presence-service Patch
@rocket.chat/abac Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/license Patch
@rocket.chat/media-calls Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/network-broker Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch
@rocket.chat/server-fetch Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 24, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fe0838c4-a248-4388-8fa8-03661746d284

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.80%. Comparing base (72fb0bd) to head (43e6955).
⚠️ Report is 3 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #40306      +/-   ##
===========================================
- Coverage    69.81%   69.80%   -0.02%     
===========================================
  Files         3296     3297       +1     
  Lines       119173   119269      +96     
  Branches     21468    21509      +41     
===========================================
+ Hits         83198    83251      +53     
- Misses       32675    32703      +28     
- Partials      3300     3315      +15     
Flag Coverage Δ
e2e 59.69% <71.42%> (-0.06%) ⬇️
e2e-api 46.24% <ø> (-0.03%) ⬇️
unit 70.56% <78.68%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rc-layne
Copy link
Copy Markdown

rc-layne Bot commented Apr 27, 2026

Layne — scan passed

No security issues found on latest push.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to prevent the client-side message parsing pipeline from causing severe performance issues (up to “breaking” the workspace) when handling very large message payloads, by introducing a maximum parse size and bypassing parsing/rendering paths when the content exceeds that threshold.

Changes:

  • Introduces a useMaxMessageParseSize hook based on the Message_MaxAllowedSize setting, capped by a new hard limit constant.
  • Updates message normalization/body hooks to skip parsing when msg.length exceeds the max parse size (falling back to raw text / a minimal AST).
  • Wires the new limit through message rendering variants and quote attachment rendering, and adds unit tests for the new behavior.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
apps/meteor/client/views/room/MessageList/hooks/useMessageBody.tsx Adds maxMessageParseSize parameter and bypasses parsing for oversized messages.
apps/meteor/client/views/room/MessageList/hooks/useMessageBody.spec.ts Adds unit tests validating the new bypass behavior and parser invocation conditions.
apps/meteor/client/lib/constants.ts Introduces MESSAGE_PARSE_HARD_LIMIT constant used to cap parsing size.
apps/meteor/client/components/message/variants/thread/ThreadMessageContent.tsx Passes max parse size into normalization to avoid parsing oversized messages in thread view.
apps/meteor/client/components/message/variants/room/RoomMessageContent.tsx Passes max parse size into normalization to avoid parsing oversized messages in room view.
apps/meteor/client/components/message/variants/ThreadMessagePreview.tsx Uses max parse size when computing preview body to avoid parsing oversized parent messages.
apps/meteor/client/components/message/hooks/useNormalizedMessage.ts Adds max-size bypass; returns minimal md AST for oversized messages.
apps/meteor/client/components/message/hooks/useNormalizedMessage.spec.ts Adds tests ensuring parsing is skipped for oversized messages and attachments are preserved.
apps/meteor/client/components/message/hooks/useMaxMessageParseSize.ts New hook computing max parse size from settings with a hard cap.
apps/meteor/client/components/message/content/attachments/QuoteAttachment.tsx Avoids rendering parsed md for oversized quote attachment text.
apps/meteor/client/components/message/content/attachments/QuoteAttachment.spec.tsx Adds tests for quote attachment md rendering vs plain-text fallback based on size.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/meteor/client/components/message/hooks/useNormalizedMessage.ts Outdated
Comment thread apps/meteor/client/components/message/content/attachments/QuoteAttachment.tsx Outdated
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.

2 participants