Skip to content

refactor(ui): extract markdown render owners#683

Merged
Astro-Han merged 3 commits into
devfrom
codex/ui-markdown-render-owners
May 16, 2026
Merged

refactor(ui): extract markdown render owners#683
Astro-Han merged 3 commits into
devfrom
codex/ui-markdown-render-owners

Conversation

@Astro-Han
Copy link
Copy Markdown
Owner

@Astro-Han Astro-Han commented May 16, 2026

Summary

  • Governs packages/ui/src/components/markdown.tsx by extracting focused internal owners for sanitizing/fallback rendering, code block copy/link decoration, link/image click routing, task-list rewriting, and details state decoration.
  • Keeps the public Markdown component and the existing test helper exports available from ./markdown.
  • Reduces packages/ui/src/components/markdown.tsx from 598 LOC to 185 LOC.

Why

Owner lane: #601 message flow.

This is the final file-governance slice for this session. Markdown rendering is part of the message surface and had several unrelated responsibilities in one large component file. This PR makes that file reviewable without changing runtime behavior or package exports.

Related Issue

Related to #601 and #638.

Human Review Status

Pending. A human should make the final merge decision after reviewing the final diff and verification evidence.

Review Focus

  • Confirm the extracted helpers preserve markdown sanitizing, task-list rendering, link routing, details open-state preservation, code block copy buttons, and inline code URL decoration.
  • Confirm the PR only governs packages/ui/src/components/markdown.tsx and its same-directory internal helpers/tests.

Topology

File Governed

Primary governed file:

  • packages/ui/src/components/markdown.tsx

Supporting files:

  • packages/ui/src/components/markdown-sanitize.ts
  • packages/ui/src/components/markdown-code-tools.ts
  • packages/ui/src/components/markdown-link-routing.ts
  • packages/ui/src/components/markdown-task-list.ts
  • packages/ui/src/components/markdown-details.ts
  • packages/ui/src/components/markdown.test.ts

Behavior

Behavior intended unchanged. This is a structural extraction only. Public component usage remains Markdown from @opencode-ai/ui/markdown, and existing helper exports used by tests remain re-exported from ./markdown.

Tests Locking Behavior

The focused behavior tests cover:

  • DOMPurify allow/deny behavior and protocol-relative URL rejection.
  • GFM task-list checkbox sanitizing and SVG/label rewriting.
  • link routing for external URLs, local paths, anchors, dangerous schemes, protocol-relative URLs, and Windows paths.
  • code block copy button wrapping and idempotency.
  • inline code URL decoration, existing-link preservation, and unwrap behavior when text is no longer URL-shaped.
  • copy button failure handling plus timeout label reset behavior.
  • details default-open behavior and user-collapse preservation.
  • markdown streaming block behavior.

Testing Gap

No browser screenshot or Electron manual check was run because this PR is a same-behavior refactor of markdown internals with no intended visual, copy, route, IPC, or desktop shell change. Reviewers should still visually scan a rendered long assistant message if they want extra confidence in CSS/DOM parity.

Architecture Effect

  • Owner extracted: sanitize/fallback, code tools, link routing, task list, and details decoration.
  • LOC reduced: markdown.tsx 598 -> 185.
  • Behavioral tests added: code block copy decoration, inline code URL mark/unmark behavior, existing-link preservation, and copy failure/timeout behavior.
  • Public contract stabilized: existing ./markdown helper exports remain available.

Risk Notes

Behavior unchanged claim depends on the helper wiring preserving decorator order. The focused tests cover the highest-risk extracted behavior, but they do not replace a visual review of rendered markdown in the full app.

How To Verify

Diff overlap audit: no open PR touches packages/ui/src/components/markdown.tsx, markdown.test.ts, or the new markdown-* helper paths
LOC: packages/ui/src/components/markdown.tsx 598 -> 185
Focused tests: bun test src/components/markdown.test.ts src/components/markdown-stream.test.ts -> 44 passed
Typecheck: bun run typecheck in packages/ui -> tsgo --noEmit passed
Lint: bun run lint -- packages/ui/src/components/markdown.tsx packages/ui/src/components/markdown-sanitize.ts packages/ui/src/components/markdown-code-tools.ts packages/ui/src/components/markdown-link-routing.ts packages/ui/src/components/markdown-task-list.ts packages/ui/src/components/markdown-details.ts -> passed
Diff check: git diff --check -> clean

Screenshots or Recordings

Not run. No intended visible UI, copy, style, route, or desktop shell behavior change.

Checklist

  • Human review status is stated above as pending, approved, or not required
  • I linked the related issue, or stated why there is no issue
  • This PR has type, primary area, and priority labels, or I requested maintainer labeling
  • I described the review focus and any meaningful risks
  • I listed the relevant verification steps and the key result for each
  • I did not introduce unrelated refactors, dependencies, generated files, or file changes beyond the stated scope
  • I manually checked visible UI or copy changes when needed, with screenshots or recordings
  • I considered macOS and Windows impact for platform, packaging, updater, signing, paths, shell, or permissions changes
  • I called out docs, release notes, dependencies, permissions, credentials, deletion behavior, generated content, or local file changes when relevant
  • I reviewed the final diff for unrelated changes and suspicious dependency changes
  • I am targeting dev, and my PR title and commit messages use Conventional Commits in English

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 16, 2026

Warning

Rate limit exceeded

@Astro-Han has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 28 minutes and 1 second before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: de75096c-7640-4bec-9f3d-151386e09760

📥 Commits

Reviewing files that changed from the base of the PR and between 361d533 and 4e8457d.

📒 Files selected for processing (7)
  • packages/ui/src/components/markdown-code-tools.ts
  • packages/ui/src/components/markdown-details.ts
  • packages/ui/src/components/markdown-link-routing.ts
  • packages/ui/src/components/markdown-sanitize.ts
  • packages/ui/src/components/markdown-task-list.ts
  • packages/ui/src/components/markdown.test.ts
  • packages/ui/src/components/markdown.tsx
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/ui-markdown-render-owners

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.

@Astro-Han Astro-Han added ui Design system and user interface tech-debt Internal cleanup and maintainability debt P2 Medium priority labels May 16, 2026
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Suggested priority: P2 (includes non-doc, non-test paths outside the low-risk bucket).

P1/P0 are reserved for maintainer confirmation. Please relabel manually if this is a release blocker, security issue, data-loss risk, or updater/runtime failure.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the Markdown component by modularizing its logic into several specialized utility files, including markdown-code-tools.ts, markdown-details.ts, markdown-link-routing.ts, markdown-sanitize.ts, and markdown-task-list.ts. The feedback focuses on preventing invalid nested anchor tags when marking code links and improving the copy button handler with better memory management, i18n safety, and error handling for clipboard operations.

Comment thread packages/ui/src/components/markdown-code-tools.ts Outdated
Comment thread packages/ui/src/components/markdown-code-tools.ts
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 16, 2026

Perf delta summary

Comparator: pass

Profile / Scenario interaction median interaction worst long task max tbt frame gap p95 frame gap max jank count cls status
default / homepage-cold 40 -> 24 (-16) 40 -> 64 (+24) 97 -> 64 (-33) 47 -> 14 (-33) 16.8 -> 16.8 (0) 166.6 -> 116.7 (-49.9) 4 -> 3 (-1) 0 -> 0 (0) pass
default / long-session-input-lag 64 -> 48 (-16) 64 -> 48 (-16) 0 -> 0 (0) 0 -> 0 (0) 16.7 -> 16.7 (0) 16.7 -> 16.8 (+0.1) 0 -> 0 (0) 0 -> 0 (0) pass
default / session-streaming-long 48 -> 40 (-8) 72 -> 72 (0) 0 -> 0 (0) 0 -> 0 (0) 16.8 -> 16.8 (0) 33.4 -> 33.3 (-0.1) 0 -> 0 (0) 0 -> 0 (0) pass
default / tool-call-expand 24 -> 24 (0) 24 -> 24 (0) 0 -> 0 (0) 0 -> 0 (0) 16.8 -> 16.7 (-0.1) 16.8 -> 16.7 (-0.1) 0 -> 0 (0) 0 -> 0 (0) pass
default / tool-default-open-heavy-bash 24 -> 24 (0) 32 -> 24 (-8) 65 -> 65 (0) 15 -> 15 (0) 50 -> 33.4 (-16.6) 116.7 -> 100.1 (-16.6) 3 -> 2 (-1) 0 -> 0 (0) pass
default / terminal-side-panel-open 48 -> 48 (0) 64 -> 56 (-8) 0 -> 0 (0) 0 -> 0 (0) 33.3 -> 33.4 (+0.1) 33.3 -> 33.4 (+0.1) 0 -> 0 (0) 0 -> 0 (0) pass
default / session-scroll-reading 24 -> 24 (0) 24 -> 24 (0) 0 -> 0 (0) 0 -> 0 (0) 16.8 -> 16.7 (-0.1) 16.8 -> 16.7 (-0.1) 0 -> 0 (0) 0.505 -> 0.505 (0) warn: cls
low-end / session-scroll-reading-long 48 -> 56 (+8) 56 -> 64 (+8) 69 -> 80 (+11) 36 -> 46 (+10) 16.8 -> 16.8 (0) 216.6 -> 183.3 (-33.3) 3 -> 3 (0) 0.011 -> 0.011 (0) pass
low-end / session-timeline-recompute 128 -> 120 (-8) 152 -> 128 (-24) 114 -> 109 (-5) 202 -> 168 (-34) 99.9 -> 99.9 (0) 183.4 -> 183.2 (-0.2) 3 -> 3 (0) 0.081 -> 0.081 (0) pass
low-end / concurrent-shimmer-extreme 0 -> 0 (0) 0 -> 0 (0) 0 -> 0 (0) 0 -> 0 (0) 16.7 -> 16.8 (+0.1) 16.8 -> 16.8 (0) 0 -> 0 (0) 0 -> 0 (0) pass

@Astro-Han Astro-Han merged commit 878c24a into dev May 16, 2026
28 checks passed
@Astro-Han Astro-Han deleted the codex/ui-markdown-render-owners branch May 16, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Medium priority tech-debt Internal cleanup and maintainability debt ui Design system and user interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant