fix(x-markdown): render placeholder for inline construct after list marker - #1995
fix(x-markdown): render placeholder for inline construct after list marker#1995zuokun300 wants to merge 2 commits into
Conversation
…arker When streaming, an inline construct (link/image) that starts right after a list marker (`- [text](`, `-  was committed as raw markdown, because the list recognizer only handed over to inline code (backticks). Extend the list recognizer to keep the token pending through the ambiguous window and hand over to the link/image recognizer once the construct is confirmed (`](` for links, `![` for images). GFM task markers ([ ]/[x]/[X]) never contain `](`, so they keep rendering as list text. Fixes ant-design#1988 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
|
Important Review skippedNo new commits to review since the last review. ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthrough更新流式 Markdown 解析中列表 token 的交接与前缀提交逻辑,使列表标记后的链接、图片和行内代码可正确识别,并新增相关回归测试及 GFM 任务列表测试。 Changes列表后的行内结构流式解析
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/x-markdown/src/XMarkdown/__tests__/streaming-list-inline.test.tsx (1)
35-58: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win补齐
*和+列表标记的回归覆盖。当前所有用例都使用
-,但本次逻辑明确覆盖-、*、+三种标记。建议将链接、图片和行内代码用例参数化到三种前缀,避免某一种列表标记的交接逻辑回归。🤖 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/x-markdown/src/XMarkdown/__tests__/streaming-list-inline.test.tsx` around lines 35 - 58, Extend the inline construct tests in the “#1988 inline construct right after a list marker” suite to cover -, *, and + list markers. Parameterize the link, image, and inline-code cases so each prefix verifies the same placeholder output while preserving the existing raw inline content and behavior.
🤖 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.
Inline comments:
In `@packages/x-markdown/src/XMarkdown/hooks/useStreaming.ts`:
- Around line 132-134: Update the listPrefix matching in getCommitPrefix to
require 1–3 whitespace characters after -, +, or *, matching the
isStreamingValid rule; preserve the existing prefix extraction and handoff
behavior for valid GFM list markers.
- Around line 123-125: Update the task-marker checks in both isStreamingValid
and getCommitPrefix to require a whitespace character or end of input after the
closing bracket, using the shared boundary behavior ^\[[ xX]\](?:\s|$). Add
regression coverage for markers followed immediately by link text such as
“(htt”, while preserving valid task-marker handling.
---
Nitpick comments:
In `@packages/x-markdown/src/XMarkdown/__tests__/streaming-list-inline.test.tsx`:
- Around line 35-58: Extend the inline construct tests in the “#1988 inline
construct right after a list marker” suite to cover -, *, and + list markers.
Parameterize the link, image, and inline-code cases so each prefix verifies the
same placeholder output while preserving the existing raw inline content and
behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 76b89158-8862-4167-9254-63bf73c392cc
📒 Files selected for processing (2)
packages/x-markdown/src/XMarkdown/__tests__/streaming-list-inline.test.tsxpackages/x-markdown/src/XMarkdown/hooks/useStreaming.ts
Address CodeRabbit review on ant-design#1988: "[x](url)" is a link whose label is "x", not a GFM task marker. Decide by what follows "]" (whitespace = task, "](" = link) instead of end-of-buffer, so a marker is not settled before its "(" arrives during char-by-char streaming. Align getCommitPrefix's list-prefix rule with isStreamingValid (require trailing whitespace). Add regression tests for [x] / [X] / [ ] single-char labels.
|
@coderabbitai review Both findings addressed in 672011d. Note the reply on the first thread: the suggested |
🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '== PR head and referenced commit =='
git status --short
git show --no-ext-diff --format=fuller --stat 672011d
git show --no-ext-diff --format= --find-renames 672011d -- \
packages/x-markdown/src/XMarkdown/hooks/useStreaming.ts \
packages/x-markdown/src/XMarkdown/__tests__/streaming-list-inline.test.tsx
printf '%s\n' '== Implementation outline =='
ast-grep outline packages/x-markdown/src/XMarkdown/hooks/useStreaming.ts --items all
printf '%s\n' '== Relevant recognizer and test excerpts =='
rg -n -C 12 'tokenRecognizerMap|List:|isStreamingValid|getCommitPrefix|task|incomplete-link|incomplete-image' \
packages/x-markdown/src/XMarkdown/hooks/useStreaming.ts \
packages/x-markdown/src/XMarkdown/__tests__/streaming-list-inline.test.tsx
printf '%s\n' '== Related token definitions and recognition control flow =='
rg -n -C 8 'STREAM_INCOMPLETE_REGEX|recognize\s*\(|getCommitPrefix|isStreamingValid' \
packages/x-markdown/src/XMarkdownLength of output: 51795
🐇 ✅ ✏️ Learnings added
✅ Action performedReview finished.
|
What & Why
Fixes #1988.
While streaming, an inline construct that starts immediately after a list marker was rendered as raw markdown instead of an incomplete-token placeholder:
- [text](htt- [text](htt(raw)- <incomplete-link … />- . For a link/image the buffer stayed a "list" token, failedisStreamingValid, and was committed as plain text — so the placeholder was never produced.Fix
Extend the list recognizer only:
isStreamingValidkeeps the list token pending through the ambiguous window right after the marker, then releases it once the construct is confirmed (](for a link,![for an image).getCommitPrefixcommits just the marker prefix (-) and hands the rest to the link/image recognizer.GFM task markers (
- [ ]/- [x]/- [X]) never contain](, so they keep rendering as list text — verified explicitly in the tests. This is the case a naive "hand over on any[" would break.Tradeoff (worth a maintainer's eye)
For a link inside a list there is now a brief "blank" window from
- [until](arrives (the label is held, not shown as raw). This mirrors how the library already holds an incomplete emphasis in a list (- **boldrenders nothing until closed), so it is consistent with existing behavior — but flagging it in case a different UX is preferred.Scope
1. [text]() were not affected (they don't go through the list recognizer) and continue to work.*,+) and indented list items are covered.Testing
New
streaming-list-inline.test.tsx(9 cases). Verified red→green:hooks.test.tsxsuite (96 cases) stays green — no regression.Summary by CodeRabbit
!等异常输出。[ ]/[x]/[X]及其变体)识别准确性,避免与链接占位符混淆;流式中途的裸任务标记会暂挂,结束后再正确渲染。