fix(sender): support formatResult for content slot type - #1986
Conversation
Previously, the function in short-circuited on type slots, returning raw and bypassing . This made slots inconsistent with other slot types (input, select, tag, custom) which all honor . This fix removes the special-case early return for type and routes it through the same pipeline, using the DOM as the input value (since content slots are contenteditable and their live value lives in the DOM, not in state). Changes: - Modified to apply to content type - Added unit tests in - Added component integration tests in - Added demo showcasing formatResult on content slots - Updated API docs in and Closes ant-design#1956
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (7)
📝 WalkthroughWalkthroughSender 的 ChangesSender content 格式化
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant Sender
participant getNodeTextValue
participant formatResult
User->>Sender: 编辑 content 插槽
User->>Sender: 点击 Get Value 或提交
Sender->>getNodeTextValue: 读取插槽值
getNodeTextValue->>formatResult: 格式化 content 值
formatResult-->>Sender: 返回格式化文本
Sender-->>User: 展示 getValue 或提交结果
Possibly related PRs
Suggested labels: 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.
Code Review
This pull request enables the 'formatResult' option to apply to all slot types, including the 'content' type, in the 'Sender' component. Previously, 'content' type slots bypassed 'formatResult' and returned raw text content. The changes update 'useSlotConfigState' to retrieve the DOM text content for 'content' slots and pass it through 'formatResult' if defined. Additionally, a new demo ('slot-format-result'), corresponding documentation updates, and comprehensive unit tests have been added to verify this behavior. There are no review comments, so I have no feedback to provide on reviewer comments.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Issue
Closes #1956
Background
In slot mode, the source code made a special case for
contenttype slots, skipping theformatResultformatting logic. This causedcontentslots to return rawtextContentinstead of a formatted value, making them inconsistent with other slot types (input,select,tag,custom) which all honorformatResult.Problem
In
packages/x/components/sender/hooks/use-slot-config-state.ts(~L171), thegetNodeTextValuefunction short-circuited oncontenttype:Solution
Removed the special-case early return for
contenttype. Now content slots go through the sameformatResultpipeline as other types, using the DOMtextContentas the input value (since content slots arecontenteditableand their live value lives in the DOM, not in state).Acceptance Criteria
formatResultChanges
hooks/use-slot-config-state.ts__tests__/use-slot-config-state.test.ts__tests__/slot.test.tsxdemo/slot-format-result.tsx+.mdindex.zh-CN.md/index.en-US.mdTest Results
All 195 sender tests passed (0 failures).
Summary by CodeRabbit
新功能
formatResult现支持格式化所有词槽类型,包括内容词槽。文档
formatResult的适用范围及示例说明。Bug 修复
formatResult时未应用格式化结果的问题。