refactor(web): chat markdown code blocks live in their own module#22690

merged1
main
refactor/chat-markdown-code-blocks
opened3d agobyJJulius Marminge
View on GitHubTwo-way sync enabledPR last imported 3d ago

ChatMarkdown.tsx was a 3,560-line file that held every markdown renderer. This stack splits it into focused modules so each piece is readable on its own.

The code block, its frame and the Shiki renderers move to chat/MarkdownCodeBlock.tsx, along with the highlight cache. The fence parsing helpers move to MarkdownCodeBlock.logic.ts. The shared action-failure logger moves to chat/markdownActionFailure.ts. ComposerCodeBlockNodeView now imports MarkdownCodeBlockFrame from the new module.

This is a pure move. Each renderer was already its own component, so no render boundary changes. Behavior is unchanged.

BeforeAfter
ChatMarkdown.tsx lines35603069
New fileschat/MarkdownCodeBlock.tsx (390), MarkdownCodeBlock.logic.ts (119), markdownActionFailure.ts (15)
Rendersunchanged: no component, subscription or context boundary movedunchanged

Renders were not measured for this layer. It changes no render boundaries: the components, their props, and the two contexts stay exactly as they were.

Tests run:

  • vp test run --project browser src/components/ChatMarkdown.browser.test.tsx src/components/ChatMarkdown.permissions.browser.test.tsx (11 passed)
  • vp test run --project unit src/reactCompilerCoverage.test.ts for every touched file (0 bailouts)
  • tsc --noEmit for apps/web, and vp lint on changed files

🤖 Generated with Claude Code

Checks

All checks passed
Synced from GitHub

Approvability

Verdict: Approved at 1791171

Macroscope's review found this PR approvable — This PR mechanically extracts existing chat markdown code-block components and helpers into focused modules while preserving their implementations, props, state behavior, and render paths. The only other runtime change is an equivalent import-path update for the composer frame, with no product-default or static-analysis configuration changes.

No code changes detected at eadb13d. Prior analysis still applies.

You can add or adjust custom eligibility rules. Learn more.

Synced from GitHub

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Path: .coderabbit.config.ts
  • Review profile: CHILL
  • Plan: Team
  • Run ID: a6c9586b-99ae-40f0-9a4f-d625988561fc
📥 Commits

Reviewing files that changed from the base of the PR and between 6a6c84f9906cbdfa7f533fecfc39ce18c2f4c273 and 17911714648b1debf9d6d6fc4fea6c95bf86f83d.

📒 Files selected for processing: 5
  • apps/web/src/components/ChatMarkdown.tsx
  • apps/web/src/components/chat/ComposerCodeBlockNodeView.tsx
  • apps/web/src/components/chat/MarkdownCodeBlock.logic.ts
  • apps/web/src/components/chat/MarkdownCodeBlock.tsx
  • apps/web/src/components/chat/markdownActionFailure.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

📝 Walkthrough

Code-block parsing, rendering, highlighting, and action-failure reporting moved from ChatMarkdown.tsx into dedicated chat modules. The shared renderer provides copy, wrapping, shell execution, diagram controls, streaming-aware highlighting, fallback rendering, and bounded caching. ComposerCodeBlockNodeView now imports the shared frame from its local module.

Changes: Markdown code-block rendering

Layer / File(s)Summary
Code-block parsing and cache utilities
apps/web/src/components/chat/MarkdownCodeBlock.logic.ts
Utilities extract fence language and titles, read code metadata, detect closed fences, flatten and validate code nodes, and create highlight cache keys and size estimates.
Code-block rendering and highlighting
apps/web/src/components/chat/MarkdownCodeBlock.tsx, apps/web/src/components/chat/markdownActionFailure.ts
The shared renderer provides framing, titles, copy and wrap controls, validated shell execution, diagram controls, streaming-aware highlighting, bounded caching, and fallback rendering. A shared function logs action failures with operation context and causes.
Markdown and composer integration
apps/web/src/components/ChatMarkdown.tsx, apps/web/src/components/chat/ComposerCodeBlockNodeView.tsx
ChatMarkdown.tsx imports the shared modules and removes its local code-block and highlighting implementations. ComposerCodeBlockNodeView imports the shared frame from its local module.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Suggested reviewers: maria-rcks

Merge Risk: ⚪ Minimal · up to 17911

This is a behavior-preserving refactor that splits code-block rendering out of the large chat markdown file. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check nameStatusExplanationResolution
Description checkWarningThe description explains the problem, change, behavior-preservation goal, and verification results. It does not provide the required Scope and approval information, and it does not clearly identify bo…Add the triaged issue or maintainer approval with its discussion or approval comment. If no prior issue or discussion exists, explain why this focused refactor qualifies for an exemption. End with the model and harness used to perform the w…
Passed Passed checks: 3 passed
Check nameStatusExplanation
Title checkPassedThe title clearly and concisely describes the primary change: moving chat markdown code blocks into a dedicated module.
Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the problem, change, behavior-preservation goal, and verification results. It does not provide the required Scope and approval information, and it does not clearly identify both the model and harness used.

Resolution

Add the triaged issue or maintainer approval with its discussion or approval comment. If no prior issue or discussion exists, explain why this focused refactor qualifies for an exemption. End with the model and harness used to perform the work.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Added 1 commit

  • refactor(web): chat markdown code blocks live in their own moduleeadb13d