Skip to content

getTargetContainer getPopupContainer support ShadowRoot type#55278

Merged
afc163 merged 2 commits intoant-design:masterfrom
leshalv:patch-3
Oct 15, 2025
Merged

getTargetContainer getPopupContainer support ShadowRoot type#55278
afc163 merged 2 commits intoant-design:masterfrom
leshalv:patch-3

Conversation

@leshalv
Copy link
Copy Markdown
Contributor

@leshalv leshalv commented Oct 12, 2025

中文版模板 / Chinese template

🤔 This is a ...

  • 🆕 New feature
  • 🐞 Bug fix
  • 📝 Site / documentation improvement
  • 📽️ Demo improvement
  • 💄 Component style improvement
  • 🤖 TypeScript definition improvement
  • 📦 Bundle size optimization
  • ⚡️ Performance optimization
  • ⭐️ Feature enhancement
  • 🌐 Internationalization
  • 🛠 Refactoring
  • 🎨 Code style optimization
  • ✅ Test Case
  • 🔀 Branch merge
  • ⏩ Workflow
  • ⌨️ Accessibility improvement
  • ❓ Other (about what?)

🔗 Related Issues

  • Describe the source of related requirements, such as links to relevant issue discussions.
  • For example: close #xxxx, fix #xxxx

💡 Background and Solution

  • The specific problem to be addressed.
  • List the final API implementation and usage if needed.
  • If there are UI/interaction changes, consider providing screenshots or GIFs.

📝 Change Log

Language Changelog
🇺🇸 English
🇨🇳 Chinese

Signed-off-by: smallbun <30397655+leshalv@users.noreply.github.com>
@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Oct 12, 2025

👁 Visual Regression Report for PR #55278 Passed ✅

🎯 Target branch: master (450c2b2)
📖 View Full Report ↗︎
📖 Alternative Report ↗︎

🎊 Congrats! No visual-regression diff found.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Oct 12, 2025

Preview is ready

@github-actions
Copy link
Copy Markdown
Contributor

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @leshalv, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the ConfigProviderProps interface by extending the type definitions for getTargetContainer and getPopupContainer. These functions can now return a ShadowRoot element, which improves compatibility and flexibility when integrating with web components and shadow DOM environments.

Highlights

  • Type Definition Update: The getTargetContainer prop in ConfigProviderProps now supports ShadowRoot as a return type, alongside HTMLElement and Window.
  • Type Definition Update: The getPopupContainer prop in ConfigProviderProps now supports ShadowRoot as a return type, in addition to HTMLElement.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 12, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Summary by CodeRabbit

  • 新功能
    • 现已支持将目标容器与弹出容器挂载到 Shadow DOM,提升在 Web Components、微前端等场景下的浮层渲染与定位兼容性。
  • 测试
    • 更新用例以覆盖 Shadow DOM 容器挂载与渲染路径,确保现有交互与样式行为保持一致。

Walkthrough

components/config-provider/index.tsx 中,扩展了 ConfigProviderProps 的两个回调类型:getTargetContainer 允许返回 HTMLElement | Window | ShadowRootgetPopupContainer 允许返回 HTMLElement | ShadowRoot。同时在 components/image/__tests__/index.test.tsx 中,对 getPopupContainer 的返回值在测试中加了 as HTMLElement 的类型断言。未修改运行时行为或控制流,仅为类型签名与测试类型断言的调整。

Changes

Cohort / File(s) Change Summary
类型签名扩展(ConfigProviderProps)
components/config-provider/index.tsx
放宽 getTargetContainer 返回类型为 `HTMLElement
测试类型断言调整
components/image/__tests__/index.test.tsx
在测试中将 getPopupContainer 返回值使用 as HTMLElement 做类型断言以满足更严格的类型检查。无行为改动。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

小兔闻风跳一跃,影根同入代码约。
容器更广心更宽,测试断言添一抹。 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning 当前描述仅为项目默认模板内容,未针对本次 PR 的类型签名扩展和 ShadowRoot 支持等关键信息做任何说明,与实际变更内容无关。 请使用简要的文字说明本次 PR 所做的具体改动背景、实现方案及使用示例,并补充更新日志,以便评审者快速理解变更内容。
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed 标题准确概述了主要改动,即为 getTargetContainer 和 getPopupContainer 增加 ShadowRoot 类型支持,清晰且与变更内容一致。
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link
Copy Markdown
Contributor

@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 adds support for ShadowRoot as a return type for getTargetContainer and getPopupContainer in ConfigProvider. This is a useful enhancement for using antd components within a Shadow DOM. However, the change is incomplete. The corresponding types in the config context and the API documentation have not been updated. Additionally, there are no tests to validate this new functionality. I've left a comment with suggestions to address these points to make the change complete.

Comment thread components/config-provider/index.tsx
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 12, 2025

Bundle Report

Bundle size has no change ✅

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Oct 12, 2025

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 450c2b2 and 95b6956.

📒 Files selected for processing (1)
  • components/config-provider/index.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use TypeScript and React for implementation
Use early returns to improve readability
Props and variable names use camelCase
Props naming: initialization as default + PropName (e.g., defaultValue)
Props naming: forceRender for forced render
Props naming: child force render as force + SubComponentName + Render
Props naming: child render as SubComponentName + Render
Props naming: dataSource for data source
Props naming: use open instead of visible for open state
Props naming: display-related as show + PropName
Props naming: capability as PropName + able
Props naming: disabled for disabled state
Props naming: extra for extra content
Props naming: icon for icon
Props naming: trigger for trigger elements
Props naming: className for CSS class
Event naming: on + EventName
Event naming: child component events on + SubComponentName + EventName
Event naming: before + EventName for pre events
Event naming: after + EventName for post events
Event naming: on + EventName + Complete for completion
Component token naming: variant(optional) + semantic parts + css property + size/disabled(optional)
Provide accurate TypeScript types for all components and functions
Avoid any; prefer precise types
Use interfaces instead of type aliases for object shapes
Export all public interface types
No TypeScript errors or warnings in compilation
Component props must be defined with interface named ComponentNameProps
Define component state interfaces like ComponentNameState where applicable
All callback types must declare parameter and return types explicitly
Use generics appropriately for flexibility
Use intersection types (&) to combine types when needed
Use literal union types for finite option sets
Avoid enum; prefer union types with as const
Prefer type inference; use assertions only when necessary

Files:

  • components/config-provider/index.tsx
**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

**/*.tsx: Prefer functional components and Hooks; avoid class components
Use React.memo, useMemo, and useCallback appropriately for performance
Component names use PascalCase
Components should expose a ref prop with shape { nativeElement: HTMLElement; focus: VoidFunction; ... }
Component ref types should be explicit using React.ForwardRefRenderFunction
Avoid unnecessary re-renders; optimize style computation; optimize assets; support tree-shaking

Files:

  • components/config-provider/index.tsx
components/**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

Use useLocale exported from components/locale/index.tsx to read localized strings and merge with prop locale

Files:

  • components/config-provider/index.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: build preview
  • GitHub Check: build
  • GitHub Check: build
  • GitHub Check: test-react-latest (dom, 2/2)
  • GitHub Check: test lib/es module (es, 2/2)
  • GitHub Check: test-react-latest (dom, 1/2)
  • GitHub Check: test lib/es module (es, 1/2)
  • GitHub Check: visual-diff snapshot (1/2)
  • GitHub Check: test-react-legacy (17, 2/2)
  • GitHub Check: test-react-legacy (16, 2/2)
  • GitHub Check: visual-diff snapshot (2/2)
  • GitHub Check: test-react-legacy (17, 1/2)
  • GitHub Check: test-react-legacy (16, 1/2)
  • GitHub Check: size

Comment on lines +145 to +146
getTargetContainer?: () => HTMLElement | Window | ShadowRoot;
getPopupContainer?: (triggerNode?: HTMLElement) => HTMLElement | ShadowRoot;
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.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

类型扩展支持 Shadow DOM,需验证下游消费者。

类型扩展为 ShadowRoot 是向后兼容的改动,支持 Web Components 场景。但需要确保:

  1. ConfigConsumerProps 接口(从 ./context 导入)中的对应类型也已同步更新
  2. 所有使用这些回调的组件(如 Modal、Drawer、Tooltip、Popover、Dropdown 等)能够正确处理 ShadowRoot 作为容器节点

运行以下脚本验证类型定义的一致性和使用情况:


🏁 Script executed:

#!/bin/bash
# 验证 ConfigConsumerProps 接口中的类型定义是否已同步更新

echo "=== 检查 context.tsx 中的 ConfigConsumerProps 定义 ==="
ast-grep --pattern $'export interface ConfigConsumerProps {
  $$$
  getTargetContainer?: $RETURN_TYPE
  $$$
}'

ast-grep --pattern $'export interface ConfigConsumerProps {
  $$$
  getPopupContainer?: $RETURN_TYPE
  $$$
}'

echo -e "\n=== 查找 getTargetContainer 的使用位置 ==="
rg -n --type=ts --type=tsx -C3 'getTargetContainer' -g '!node_modules' -g '!*.test.*' -g '!*.spec.*'

echo -e "\n=== 查找 getPopupContainer 的使用位置 ==="
rg -n --type=ts --type=tsx -C3 'getPopupContainer' -g '!node_modules' -g '!*.test.*' -g '!*.spec.*'

echo -e "\n=== 检查可能受影响的 Overlay 相关组件 ==="
fd -e tsx -e ts 'modal|drawer|tooltip|popover|dropdown|popup' components/

Length of output: 1842


继续验证 ConfigConsumerProps 接口定义是否已包含 ShadowRoot。


🏁 Script executed:

#!/bin/bash
# 查找并打印 ConfigConsumerProps 接口定义
context_file=$(fd -e tsx -e ts 'context.tsx')
echo "Context file: $context_file"
sed -n '1,200p' "$context_file" | sed -n '/export interface ConfigConsumerProps/,/}/p'

Length of output: 686


继续验证 ConfigConsumerProps 接口定义是否已包含 ShadowRoot


🏁 Script executed:

#!/bin/bash
# 查找并打印 components/config-provider 下定义 ConfigConsumerProps 的文件及接口内容
echo "ConfigConsumerProps 定义文件路径:"
fd -e tsx 'ConfigConsumerProps' components/config-provider

echo -e "\n接口定义内容:"
fd -e tsx 'ConfigConsumerProps' components/config-provider | xargs sed -n '/export interface ConfigConsumerProps/,/}/p'

Length of output: 36


继续查找 ConfigConsumerProps 定义位置:


🏁 Script executed:

#!/bin/bash
# 全局查找 ConfigConsumerProps 定义
echo "=== 全局查找 ConfigConsumerProps ==="
rg -n "ConfigConsumerProps" -g "!node_modules"

Length of output: 5088


继续验证 ConfigConsumerProps 接口定义是否已包含 ShadowRoot


🏁 Script executed:

#!/bin/bash
# 打印 ConfigConsumerProps 接口定义
sed -n '/^export interface ConfigConsumerProps/,/^}/p' components/config-provider/context.ts

Length of output: 916


在 context.ts 中同步扩展容器返回类型

components/config-provider/context.tsConfigConsumerProps 接口修改为:

getTargetContainer?: () => HTMLElement | Window | ShadowRoot;
getPopupContainer?: (triggerNode?: HTMLElement) => HTMLElement | ShadowRoot;

以匹配 ConfigProviderProps 中的类型扩展。

🤖 Prompt for AI Agents
In components/config-provider/index.tsx around lines 145 to 146, the exported
function types allow getTargetContainer to return HTMLElement | Window |
ShadowRoot and getPopupContainer to return HTMLElement | ShadowRoot; update the
matching interface in components/config-provider/context.ts
(ConfigConsumerProps) so its getTargetContainer?: () => HTMLElement | Window |
ShadowRoot and getPopupContainer?: (triggerNode?: HTMLElement) => HTMLElement |
ShadowRoot, ensuring any imports/types referenced remain valid and run
type-checks to catch any downstream mismatches.

@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (450c2b2) to head (27ebe4d).
⚠️ Report is 17 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master    #55278   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          776       776           
  Lines        14122     14122           
  Branches      3752      3752           
=========================================
  Hits         14122     14122           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
components/image/__tests__/index.test.tsx (1)

92-94: 考虑使用泛型参数替代类型断言以提升代码清晰度。

当前实现使用了双重断言(!as HTMLElement),虽然功能正确,但可以通过 querySelector 的泛型参数来简化,使意图更加明确。

应用以下修改来改进代码:

         <ConfigProvider
-          getPopupContainer={() => document.querySelector('.container')! as HTMLElement}
+          getPopupContainer={() => document.querySelector<HTMLElement>('.container')!}
         >
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 95b6956 and 27ebe4d.

📒 Files selected for processing (1)
  • components/image/__tests__/index.test.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use TypeScript and React for implementation
Use early returns to improve readability
Props and variable names use camelCase
Props naming: initialization as default + PropName (e.g., defaultValue)
Props naming: forceRender for forced render
Props naming: child force render as force + SubComponentName + Render
Props naming: child render as SubComponentName + Render
Props naming: dataSource for data source
Props naming: use open instead of visible for open state
Props naming: display-related as show + PropName
Props naming: capability as PropName + able
Props naming: disabled for disabled state
Props naming: extra for extra content
Props naming: icon for icon
Props naming: trigger for trigger elements
Props naming: className for CSS class
Event naming: on + EventName
Event naming: child component events on + SubComponentName + EventName
Event naming: before + EventName for pre events
Event naming: after + EventName for post events
Event naming: on + EventName + Complete for completion
Component token naming: variant(optional) + semantic parts + css property + size/disabled(optional)
Provide accurate TypeScript types for all components and functions
Avoid any; prefer precise types
Use interfaces instead of type aliases for object shapes
Export all public interface types
No TypeScript errors or warnings in compilation
Component props must be defined with interface named ComponentNameProps
Define component state interfaces like ComponentNameState where applicable
All callback types must declare parameter and return types explicitly
Use generics appropriately for flexibility
Use intersection types (&) to combine types when needed
Use literal union types for finite option sets
Avoid enum; prefer union types with as const
Prefer type inference; use assertions only when necessary

Files:

  • components/image/__tests__/index.test.tsx
**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

**/*.tsx: Prefer functional components and Hooks; avoid class components
Use React.memo, useMemo, and useCallback appropriately for performance
Component names use PascalCase
Components should expose a ref prop with shape { nativeElement: HTMLElement; focus: VoidFunction; ... }
Component ref types should be explicit using React.ForwardRefRenderFunction
Avoid unnecessary re-renders; optimize style computation; optimize assets; support tree-shaking

Files:

  • components/image/__tests__/index.test.tsx
**/__tests__/**/?(*.)test.tsx

📄 CodeRabbit inference engine (AGENTS.md)

**/__tests__/**/?(*.)test.tsx: Use Jest and React Testing Library for unit tests
Use snapshot testing for UI components where appropriate
Test files should be named index.test.tsx or xxx.test.tsx under tests

Files:

  • components/image/__tests__/index.test.tsx
components/**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

Use useLocale exported from components/locale/index.tsx to read localized strings and merge with prop locale

Files:

  • components/image/__tests__/index.test.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (15)
  • GitHub Check: lint
  • GitHub Check: test lib/es module (es, 2/2)
  • GitHub Check: test lib/es module (es, 1/2)
  • GitHub Check: test-react-legacy (16, 2/2)
  • GitHub Check: test-react-legacy (16, 1/2)
  • GitHub Check: build
  • GitHub Check: test-react-latest (dom, 1/2)
  • GitHub Check: test-react-legacy (17, 1/2)
  • GitHub Check: test-react-latest (dom, 2/2)
  • GitHub Check: test-react-legacy (17, 2/2)
  • GitHub Check: build preview
  • GitHub Check: build
  • GitHub Check: visual-diff snapshot (2/2)
  • GitHub Check: visual-diff snapshot (1/2)
  • GitHub Check: size

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Oct 15, 2025
@afc163 afc163 merged commit 95bca1c into ant-design:master Oct 15, 2025
42 of 43 checks passed
@li-jia-nan
Copy link
Copy Markdown
Member

看一下 coderabbitai 评论,还有一个地方没改

@li-jia-nan
Copy link
Copy Markdown
Member

看一下 coderabbitai 评论,还有一个地方没改

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

Labels

lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants