feat(message-parser): block fallback for unsupported renderers#41110
Conversation
|
Looks like this PR is ready to merge! 🎉 |
WalkthroughThis PR adds fallback rendering for message blocks lacking dedicated renderers. The message-parser package introduces a ChangesFallback Rendering Feature
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Parser as parseMessageTextToAstMarkdown
participant Content as RoomMessageContent / ThreadMessageContent
participant Body as MessageContentBody
participant Markup as Markup / PreviewMarkup
Parser->>Content: normalizedMessage.mdSource
Content->>Body: msg = mdSource
Body->>Markup: source = msg
Markup->>Markup: default case - check block.fallback [start, end]
Markup->>Markup: slice source and render raw text
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
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 |
🦋 Changeset detectedLatest commit: 50302fb The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
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 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #41110 +/- ##
===========================================
+ Coverage 69.14% 70.04% +0.90%
===========================================
Files 3433 3369 -64
Lines 132323 130321 -2002
Branches 23091 22650 -441
===========================================
- Hits 91489 91288 -201
+ Misses 37472 35709 -1763
+ Partials 3362 3324 -38
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
When a block has no dedicated renderer, render its optional `fallback` plain-text node as a paragraph instead of returning null, mirroring the existing inline fallback handling. Lets unsupported blocks degrade to their original markup rather than being dropped.
99021b1 to
8f5920b
Compare
Block fallback is now a [start, end] offset span instead of inline text. Markup/PreviewMarkup take an optional `source` prop (the original message text) and slice it to render the raw markup for blocks without a dedicated renderer.
Thread the original message text (msg) into MessageContentBody and on to gazzodown's Markup as `source`, so blocks without a dedicated renderer can slice the source to show their raw markup via the parser fallback offsets.
Expose mdSource (the translation/E2EE-aware text that md was parsed from) from parseMessageTextToAstMarkdown and pass it as the Markup source, so fallback offsets slice against the right string for translated messages too.
Type the block fallback as the union of the new offset span and the original form, and narrow with Array.isArray before slicing the source. The non-array (original) form is intentionally ignored.
Emit the Timestamp `fallback` as a [start, end] source-offset span (via the grammar's range()), matching the other blocks. The field type keeps the previous `Plain` form so already-persisted data still type-checks and is ignored at render time.
The function now returns mdSource; update the full-object toStrictEqual assertions for translated messages to include it.
362f3db to
a2f2866
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/gazzodown/src/Markup.tsx (1)
68-78: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract shared fallback-resolution logic.
This fallback extraction/slicing logic (type-cast,
Array.isArraycheck, slice into aPLAIN_TEXTinline) is duplicated verbatim inPreviewMarkup.tsx(lines 89-98). Consider extracting a small shared helper (e.g.resolveFallbackText(block, source)returning the sliced string orundefined) so both components stay in sync as the fallback contract evolves.♻️ Proposed shared helper
// packages/gazzodown/src/getBlockFallbackText.ts import type * as MessageParser from '`@rocket.chat/message-parser`'; export const getBlockFallbackText = (block: unknown, source?: string): string | undefined => { const { fallback } = block as { fallback?: [number, number] | MessageParser.Plain }; if (Array.isArray(fallback) && source !== undefined) { return source.slice(fallback[0], fallback[1]); } return undefined; };+import { getBlockFallbackText } from './getBlockFallbackText'; ... - default: { - // Graceful degradation: blocks may carry a `fallback`. The current form is a - // `[start, end]` offset span into the source (sliced to render the raw markup); - // the union keeps the original form too, which we intentionally ignore. - const { fallback } = block as { fallback?: [number, number] | MessageParser.Plain }; - if (Array.isArray(fallback) && source !== undefined) { - const inlines: MessageParser.Inlines[] = [{ type: 'PLAIN_TEXT', value: source.slice(fallback[0], fallback[1]) }]; - return <ParagraphBlock key={index}>{inlines}</ParagraphBlock>; - } - return null; - } + default: { + const text = getBlockFallbackText(block, source); + if (text === undefined) return null; + return <ParagraphBlock key={index}>{[{ type: 'PLAIN_TEXT', value: text }]}</ParagraphBlock>; + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/gazzodown/src/Markup.tsx` around lines 68 - 78, The fallback extraction logic in Markup.tsx is duplicated in PreviewMarkup.tsx, so extract the shared `fallback` resolution into a small helper and reuse it from both render paths. Move the type-cast plus `Array.isArray(fallback)` and source slicing behavior into a helper such as `getBlockFallbackText` or `resolveFallbackText`, then have the `Markup` default block branch and the matching `PreviewMarkup` branch call that helper and handle the returned text/undefined consistently.apps/meteor/client/components/message/MessageContentBody.tsx (1)
10-16: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueMinor naming mismatch:
mdSourcebecomesmsg.
MessageWithMdEnforced.mdSourceis renamed tomsginMessageContentBodyProps, and then forwarded assourcetoMarkup. Functionally correct, but the three different names (mdSource→msg→source) for the same concept across layers adds cognitive overhead when tracing the data flow.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/meteor/client/components/message/MessageContentBody.tsx` around lines 10 - 16, The `MessageContentBody` props use three different names for the same value (`mdSource` on `MessageWithMdEnforced`, `msg` in `MessageContentBodyProps`, and `source` in `Markup`), which makes the data flow harder to follow. Update `MessageContentBody` and its props to use one consistent name across the component boundary and forwarding path, and make sure the symbol names in `MessageContentBodyProps` and `Markup` match the chosen convention.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@apps/meteor/client/components/message/MessageContentBody.tsx`:
- Around line 10-16: The `MessageContentBody` props use three different names
for the same value (`mdSource` on `MessageWithMdEnforced`, `msg` in
`MessageContentBodyProps`, and `source` in `Markup`), which makes the data flow
harder to follow. Update `MessageContentBody` and its props to use one
consistent name across the component boundary and forwarding path, and make sure
the symbol names in `MessageContentBodyProps` and `Markup` match the chosen
convention.
In `@packages/gazzodown/src/Markup.tsx`:
- Around line 68-78: The fallback extraction logic in Markup.tsx is duplicated
in PreviewMarkup.tsx, so extract the shared `fallback` resolution into a small
helper and reuse it from both render paths. Move the type-cast plus
`Array.isArray(fallback)` and source slicing behavior into a helper such as
`getBlockFallbackText` or `resolveFallbackText`, then have the `Markup` default
block branch and the matching `PreviewMarkup` branch call that helper and handle
the returned text/undefined consistently.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d7b48352-6278-4a7a-b1b2-92320a2e810c
📒 Files selected for processing (14)
.changeset/block-fallback-rendering.md.changeset/message-content-body-source.md.changeset/timestamp-fallback-offsets.mdapps/meteor/client/components/message/MessageContentBody.tsxapps/meteor/client/components/message/variants/room/RoomMessageContent.tsxapps/meteor/client/components/message/variants/thread/ThreadMessageContent.tsxapps/meteor/client/lib/parseMessageTextToAstMarkdown.spec.tsapps/meteor/client/lib/parseMessageTextToAstMarkdown.tspackages/gazzodown/src/Markup.tsxpackages/gazzodown/src/PreviewMarkup.tsxpackages/message-parser/src/definitions.tspackages/message-parser/src/grammar.pegjspackages/message-parser/src/utils.tspackages/message-parser/tests/timestamp.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (3)
- GitHub Check: cubic · AI code reviewer
- GitHub Check: Hacktron Security Check
- GitHub Check: 📦 Meteor Build (coverage)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation
Files:
apps/meteor/client/components/message/variants/room/RoomMessageContent.tsxapps/meteor/client/components/message/variants/thread/ThreadMessageContent.tsxapps/meteor/client/lib/parseMessageTextToAstMarkdown.tspackages/message-parser/src/definitions.tsapps/meteor/client/components/message/MessageContentBody.tsxpackages/gazzodown/src/PreviewMarkup.tsxapps/meteor/client/lib/parseMessageTextToAstMarkdown.spec.tspackages/message-parser/tests/timestamp.test.tspackages/gazzodown/src/Markup.tsxpackages/message-parser/src/utils.ts
**/*.spec.ts
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.spec.ts: Use descriptive test names that clearly communicate expected behavior in Playwright tests
Use.spec.tsextension for test files (e.g.,login.spec.ts)
Files:
apps/meteor/client/lib/parseMessageTextToAstMarkdown.spec.ts
🧠 Learnings (9)
📚 Learning: 2026-03-16T21:50:37.589Z
Learnt from: amitb0ra
Repo: RocketChat/Rocket.Chat PR: 39676
File: .changeset/migrate-users-register-openapi.md:3-3
Timestamp: 2026-03-16T21:50:37.589Z
Learning: For changes related to OpenAPI migrations in Rocket.Chat/OpenAPI, when removing endpoint types and validators from rocket.chat/rest-typings (e.g., UserRegisterParamsPOST, /v1/users.register) document this as a minor changeset (not breaking) per RocketChat/Rocket.Chat-Open-API#150 Rule 7. Note that the endpoint type is re-exposed via a module augmentation .d.ts in the consuming package (e.g., packages/web-ui-registration/src/users-register.d.ts). In reviews, ensure the changeset clearly states: this is a non-breaking change, the major version should not be bumped, and the changeset reflects a minor version bump. Do not treat this as a breaking change during OpenAPI migrations.
Applied to files:
.changeset/timestamp-fallback-offsets.md.changeset/block-fallback-rendering.md.changeset/message-content-body-source.md
📚 Learning: 2026-03-27T14:52:56.865Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39892
File: apps/meteor/client/views/room/contextualBar/Threads/Thread.tsx:150-155
Timestamp: 2026-03-27T14:52:56.865Z
Learning: In Rocket.Chat, there are two different `ModalBackdrop` components with different prop APIs. During review, confirm the import source: (1) `rocket.chat/fuselage` `ModalBackdrop` uses `ModalBackdropProps` based on `BoxProps` (so it supports `onClick` and other Box/DOM props) and does not have an `onDismiss` prop; (2) `rocket.chat/ui-client` `ModalBackdrop` uses a narrower props interface like `{ children?: ReactNode; onDismiss?: () => void }` and handles Escape keypress and outside mouse-up, and it does not forward arbitrary DOM props such as `onClick`. Flag mismatched props (e.g., `onDismiss` passed to the fuselage component or `onClick` passed to the ui-client component) and ensure the usage matches the correct component being imported.
Applied to files:
apps/meteor/client/components/message/variants/room/RoomMessageContent.tsxapps/meteor/client/components/message/variants/thread/ThreadMessageContent.tsxapps/meteor/client/components/message/MessageContentBody.tsxpackages/gazzodown/src/PreviewMarkup.tsxpackages/gazzodown/src/Markup.tsx
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.
Applied to files:
apps/meteor/client/components/message/variants/room/RoomMessageContent.tsxapps/meteor/client/components/message/variants/thread/ThreadMessageContent.tsxapps/meteor/client/lib/parseMessageTextToAstMarkdown.tspackages/message-parser/src/definitions.tsapps/meteor/client/components/message/MessageContentBody.tsxpackages/gazzodown/src/PreviewMarkup.tsxapps/meteor/client/lib/parseMessageTextToAstMarkdown.spec.tspackages/message-parser/tests/timestamp.test.tspackages/gazzodown/src/Markup.tsxpackages/message-parser/src/utils.ts
📚 Learning: 2026-02-10T16:32:42.586Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:42.586Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON and Date fields arrive as Date objects; do not manually construct new Date() in stream handlers (for example, in sdk.stream()). Only REST API responses return plain JSON where dates are strings, so implement explicit conversion there if needed. Apply this guidance to all TypeScript files under apps/meteor/client to ensure consistent date handling in DDP streams and REST responses.
Applied to files:
apps/meteor/client/lib/parseMessageTextToAstMarkdown.tsapps/meteor/client/lib/parseMessageTextToAstMarkdown.spec.ts
📚 Learning: 2026-05-11T20:30:35.265Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 40480
File: apps/meteor/client/meteor/startup/accounts.ts:59-61
Timestamp: 2026-05-11T20:30:35.265Z
Learning: In Rocket.Chat’s Meteor client code, when calling `dispatchToastMessage` with `{ type: 'error' }`, pass the raw caught error object as `message` without manual normalization. `dispatchToastMessage` is designed to accept `message: unknown` for error toasts, so avoid converting errors to strings (e.g., `String(error)`) or extracting `error.message` before passing them.
Applied to files:
apps/meteor/client/lib/parseMessageTextToAstMarkdown.tsapps/meteor/client/lib/parseMessageTextToAstMarkdown.spec.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.
Applied to files:
apps/meteor/client/lib/parseMessageTextToAstMarkdown.tspackages/message-parser/src/definitions.tsapps/meteor/client/lib/parseMessageTextToAstMarkdown.spec.tspackages/message-parser/tests/timestamp.test.tspackages/message-parser/src/utils.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.
Applied to files:
apps/meteor/client/lib/parseMessageTextToAstMarkdown.tspackages/message-parser/src/definitions.tsapps/meteor/client/lib/parseMessageTextToAstMarkdown.spec.tspackages/message-parser/tests/timestamp.test.tspackages/message-parser/src/utils.ts
📚 Learning: 2026-02-24T19:22:48.358Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 38493
File: apps/meteor/tests/e2e/omnichannel/omnichannel-send-pdf-transcript.spec.ts:66-67
Timestamp: 2026-02-24T19:22:48.358Z
Learning: In Playwright end-to-end tests (e.g., under apps/meteor/tests/e2e/...), prefer locating elements by translated text (getByText) and ARIA roles (getByRole) over data-qa attributes. If translation values change, update the corresponding test locators accordingly. Never use data-qa locators. This guideline applies to all Playwright e2e test specs in the repository and helps keep tests robust to UI text changes and accessible semantics.
Applied to files:
apps/meteor/client/lib/parseMessageTextToAstMarkdown.spec.ts
📚 Learning: 2026-03-06T18:10:15.268Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39397
File: packages/gazzodown/src/code/CodeBlock.spec.tsx:47-68
Timestamp: 2026-03-06T18:10:15.268Z
Learning: In tests (especially those using testing-library/dom/jsdom) for Rocket.Chat components, the HTML <code> element has an implicit ARIA role of 'code'. Therefore, screen.getByRole('code') or screen.findByRole('code') will locate <code> elements even without a role attribute. Do not flag findByRole('code') as invalid in reviews; prefer using the implicit role instead of adding role="code" unless necessary for accessibility.
Applied to files:
apps/meteor/client/lib/parseMessageTextToAstMarkdown.spec.ts
🔇 Additional comments (15)
packages/gazzodown/src/PreviewMarkup.tsx (2)
89-98: Same fallback-extraction logic duplicated fromMarkup.tsx.See the extraction suggestion on
Markup.tsx's default case (lines 68-78); the same helper could be reused here.
15-19: LGTM!packages/message-parser/src/definitions.ts (1)
121-125: LGTM!Also applies to: 172-181
packages/message-parser/src/grammar.pegjs (1)
112-112: LGTM!packages/message-parser/src/utils.ts (1)
20-20: LGTM!Also applies to: 291-299
packages/message-parser/tests/timestamp.test.ts (1)
11-33: LGTM!Also applies to: 44-58, 72-78
.changeset/timestamp-fallback-offsets.md (1)
1-6: LGTM!packages/gazzodown/src/Markup.tsx (1)
19-23: LGTM!.changeset/block-fallback-rendering.md (1)
1-6: LGTM!apps/meteor/client/lib/parseMessageTextToAstMarkdown.ts (1)
20-24: LGTM: mdSource wiring is straightforward and matches the fallback contract.The unconditional
mdSource: textassignment correctly captures the translation/E2EE-aware source string thatMarkup'ssourceprop expects forfallbackslicing, consistent withpackages/gazzodown/src/Markup.tsx'ssource.slice(fallback[0], fallback[1])behavior.Also applies to: 49-58
apps/meteor/client/components/message/MessageContentBody.tsx (1)
19-27: LGTM!apps/meteor/client/components/message/variants/room/RoomMessageContent.tsx (1)
65-72: LGTM!apps/meteor/client/components/message/variants/thread/ThreadMessageContent.tsx (1)
59-64: LGTM!.changeset/message-content-body-source.md (1)
1-6: LGTM!apps/meteor/client/lib/parseMessageTextToAstMarkdown.spec.ts (1)
195-195: 🎯 Functional CorrectnessNo additional
mdSourcefixture updates needed
The remaining assertions only compare.md, and the full-object expectations already includemdSource.> Likely an incorrect or invalid review comment.
There was a problem hiding this comment.
1 issue found across 14 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/gazzodown/src/PreviewMarkup.tsx">
<violation number="1" location="packages/gazzodown/src/PreviewMarkup.tsx:89">
P2: Fallback extraction and rendering logic is duplicated from `Markup.tsx`. Extract a shared helper for converting `(fallback, source)` to a `MessageParser.Inlines[]` array so that fixes to the fallback contract or rendering behavior are applied consistently in both full and preview renderers.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| ); | ||
|
|
||
| default: | ||
| default: { |
There was a problem hiding this comment.
P2: Fallback extraction and rendering logic is duplicated from Markup.tsx. Extract a shared helper for converting (fallback, source) to a MessageParser.Inlines[] array so that fixes to the fallback contract or rendering behavior are applied consistently in both full and preview renderers.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/gazzodown/src/PreviewMarkup.tsx, line 89:
<comment>Fallback extraction and rendering logic is duplicated from `Markup.tsx`. Extract a shared helper for converting `(fallback, source)` to a `MessageParser.Inlines[]` array so that fixes to the fallback contract or rendering behavior are applied consistently in both full and preview renderers.</comment>
<file context>
@@ -84,8 +86,16 @@ const PreviewMarkup = ({ tokens }: PreviewMarkupProps) => {
);
- default:
+ default: {
+ // Only the `[start, end]` offset form is rendered (sliced from source); the union
+ // keeps the original fallback form too, which we intentionally ignore.
</file context>
Proposed changes (including videos or screenshots)
Degrades block AST nodes that a renderer doesn't implement to their raw markup, instead of dropping them.
Problem
Renderers switch on
block.typewithdefault: return null. Any block type a given renderer doesn't implement is silently dropped — the content vanishes.Approach
A block may carry a
fallback: a[start, end]offset span into the original message source (see the table / horizontal-rule PRs that populate it).MarkupandPreviewMarkupnow take an optionalsourceprop (the originalmessage.msg) and, in theirdefaultbranch, slicesource[start..end]and render that text instead of returningnull.Using offsets rather than a copy of the text keeps the AST from being bloated in the persisted/transmitted payload — the source is already available next to the AST in the message. Both web and mobile (React Native) are JS, so the UTF-16 offsets slice identically on both.
Issue(s)
Consumes the
fallbackoffsets produced by the table and horizontal-rule PRs.Steps to test or reproduce
yarn turbo run build --filter=@rocket.chat/gazzodownthen typecheck. Render aMarkupwith a block carrying afallbackoffset span and asource, and confirm the raw markup is shown.Further comments
Callers that render messages should pass
source={message.msg}toMarkup/PreviewMarkupso unsupported blocks degrade to text. Mobile should adopt the samedefault.Summary by CodeRabbit
New Features
Bug Fixes