Skip to content

feat: support typewriter animation for contentRender custom components - #2014

Open
Emira798 wants to merge 1 commit into
ant-design:mainfrom
Emira798:feat/content-render-animation
Open

feat: support typewriter animation for contentRender custom components#2014
Emira798 wants to merge 1 commit into
ant-design:mainfrom
Emira798:feat/content-render-animation

Conversation

@Emira798

@Emira798 Emira798 commented Aug 5, 2026

Copy link
Copy Markdown

What does this PR do?

Adds support for typewriter animation in custom components (contentRender).

Changes

  • Added enableAnimationForCustomComponents option to StreamingOption interface
  • Updated Renderer to apply animation to text nodes inside custom components when enabled
  • Added unit tests for the new feature

Usage

sx <XMarkdown content={markdownContent} streaming={{ enableAnimation: true, enableAnimationForCustomComponents: true, }} components={{ 'content-render': MyCustomComponent, }} />

Related Issues

Closes #1950
Related to #1685

Summary by CodeRabbit

  • 新功能

    • 新增配置项,可控制自定义组件内部文本是否启用逐字动画。
    • 默认关闭该动画,保持现有行为不变。
    • 启用后,自定义组件中的有效文本节点将显示动画效果。
  • 测试

    • 新增测试,验证动画开启和关闭时的显示行为。

@dosubot dosubot Bot added enhancement New feature or request javascript Pull requests that update Javascript code labels Aug 5, 2026
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
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

新增 enableAnimationForCustomComponents 配置。启用时,自定义组件内文本使用 AnimationText;禁用或未配置时保持原行为。新增对应单元测试。

Changes

自定义组件文本动画

Layer / File(s) Summary
动画配置与渲染行为
packages/x-markdown/src/XMarkdown/interface.ts, packages/x-markdown/src/XMarkdown/core/Renderer.ts, packages/x-markdown/src/XMarkdown/__tests__/Renderer.test.ts
StreamingOption 新增可选动画开关。createReplaceElement 根据该开关处理自定义组件内文本。测试覆盖启用和禁用场景。

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • ant-design/x#1974:同样修改 Renderer.tsStreamingOptionRenderer.test.ts,用于控制自定义组件内文本动画。
  • ant-design/x#1984:包含相关的 XMarkdown 流式渲染测试和演示。
  • ant-design/x#1998:使用了本次配置所接入的 AnimationText 组件。

Suggested reviewers: div627

Poem

小兔打开动画开关,
文字一字一字跳出来。
自定义组件也不落后,
AnimationText 轻快登台。
关闭开关时,行为照旧,
代码和测试一起蹦蹦跳。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning 实现了开关、渲染逻辑和单测,但未提供 #1950 要求的 contentRender 打字机动画 demo。 补充 contentRender 与打字机动画的可运行 demo,并验证其使用方式。
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确描述了为 contentRender 自定义组件增加打字机动画支持的主要变更。
Out of Scope Changes check ✅ Passed 所有变更都围绕自定义组件文本动画、配置接口和对应单测展开,未发现无关代码。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between b529d8e and c16e23b.

📒 Files selected for processing (3)
  • packages/x-markdown/src/XMarkdown/__tests__/Renderer.test.ts
  • packages/x-markdown/src/XMarkdown/core/Renderer.ts
  • packages/x-markdown/src/XMarkdown/interface.ts

Comment on lines 185 to +190
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

修正自定义组件后代文本的判定。

第 185-190 行只检查 domNode.parent。当输入为 <content-render><span>Hello World</span></content-render> 时,文本节点的父节点是 span。即使 enableAnimationForCustomComponentsfalse,代码仍会创建 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Bundle Report

Changes will decrease total bundle size by 47 bytes (-0.0%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
antdx-array-push 2.11MB -47 bytes (-0.0%) ⬇️

Affected Assets, Files, and Routes:

view changes for bundle: antdx-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
antdx.min.js -47 bytes 2.11MB -0.0%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request javascript Pull requests that update Javascript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Good First Issue] XMarkdown contentRender 自定义渲染支持打字机效果

2 participants