feat: support typewriter animation for contentRender custom components - #2014
feat: support typewriter animation for contentRender custom components#2014Emira798 wants to merge 1 commit into
Conversation
Added enableAnimationForCustomComponents option to streaming config, so text nodes inside custom components can also have the fade-in animation. This is useful when using contentRender to customize markdown rendering while still keeping the typewriter effect. - Added enableAnimationForCustomComponents to StreamingOption interface - Updated Renderer to check this option when deciding animation - Added unit tests for the new feature Closes ant-design#1950
📝 WalkthroughWalkthrough新增 Changes自定义组件文本动画
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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: 1
🤖 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/core/Renderer.ts`:
- Around line 185-190: Update the ancestor detection in Renderer’s text-node
animation decision to traverse all domNode ancestors, not only domNode.parent,
and disable AnimationText whenever any ancestor is a configured custom component
unless enableAnimationForCustomComponents is enabled. In
packages/x-markdown/src/XMarkdown/__tests__/Renderer.test.ts:1548-1567, add or
update coverage using nested elements inside a custom component and assert that
AnimationText is not created.
🪄 Autofix
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: 5e0e2c52-4bcb-4137-9e2c-b6f8e19894b7
📒 Files selected for processing (3)
packages/x-markdown/src/XMarkdown/__tests__/Renderer.test.tspackages/x-markdown/src/XMarkdown/core/Renderer.tspackages/x-markdown/src/XMarkdown/interface.ts
| const parentTagName = (domNode.parent as Element)?.name; | ||
| const isParentCustomComponent = parentTagName && this.options.components?.[parentTagName]; | ||
| const shouldReplaceText = enableAnimation && isValidTextNode && !isParentCustomComponent; | ||
| const shouldReplaceText = | ||
| enableAnimation && | ||
| isValidTextNode && | ||
| (!isParentCustomComponent || enableAnimationForCustomComponents); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
修正自定义组件后代文本的判定。
第 185-190 行只检查 domNode.parent。当输入为 <content-render><span>Hello World</span></content-render> 时,文本节点的父节点是 span。即使 enableAnimationForCustomComponents 为 false,代码仍会创建 AnimationText。
遍历文本节点的祖先节点,并在任一祖先是已配置的自定义组件时禁止动画。添加嵌套元素的禁用场景测试。
packages/x-markdown/src/XMarkdown/core/Renderer.ts#L185-L190: 检查全部祖先节点,而不是只检查直接父节点。packages/x-markdown/src/XMarkdown/__tests__/Renderer.test.ts#L1548-L1567: 使用嵌套元素作为自定义组件内容,并断言不会创建AnimationText。
📍 Affects 2 files
packages/x-markdown/src/XMarkdown/core/Renderer.ts#L185-L190(this comment)packages/x-markdown/src/XMarkdown/__tests__/Renderer.test.ts#L1548-L1567
🤖 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/core/Renderer.ts` around lines 185 - 190,
Update the ancestor detection in Renderer’s text-node animation decision to
traverse all domNode ancestors, not only domNode.parent, and disable
AnimationText whenever any ancestor is a configured custom component unless
enableAnimationForCustomComponents is enabled. In
packages/x-markdown/src/XMarkdown/__tests__/Renderer.test.ts:1548-1567, add or
update coverage using nested elements inside a custom component and assert that
AnimationText is not created.
Bundle ReportChanges will decrease total bundle size by 47 bytes (-0.0%) ⬇️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: antdx-array-pushAssets Changed:
|
What does this PR do?
Adds support for typewriter animation in custom components (contentRender).
Changes
Usage
sx <XMarkdown content={markdownContent} streaming={{ enableAnimation: true, enableAnimationForCustomComponents: true, }} components={{ 'content-render': MyCustomComponent, }} />Related Issues
Closes #1950
Related to #1685
Summary by CodeRabbit
新功能
测试