Skip to content

feat(error-block): 支持动态生成svg元素id - #7063

Merged
zombieJ merged 8 commits into
ant-design:masterfrom
Passing-of-A-Dream:fix/error-block-svg-id
Aug 4, 2026
Merged

feat(error-block): 支持动态生成svg元素id#7063
zombieJ merged 8 commits into
ant-design:masterfrom
Passing-of-A-Dream:fix/error-block-svg-id

Conversation

@Passing-of-A-Dream

@Passing-of-A-Dream Passing-of-A-Dream commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

close #6744 为svg元素添加唯一 id 避免浏览器会跳过或错误地渲染引用元素,导致 SVG 图形显示异常

Summary by CodeRabbit

  • Bug Fixes

    • 优化错误状态插图的渲染方式,确保同一页面存在多个插图时,其 SVG 标识互不冲突。
    • 保持忙碌、默认、断开连接和空状态插图的视觉效果与现有使用方式不变。
  • Refactor

    • 统一错误提示组件及插图模块的导入和组织方式。

- 为svg元素添加唯一id避免冲突
- 修改imageRecord类型支持函数形式
- 更新所有状态图片组件接收id参数
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

四个 ErrorBlock SVG 图片改为内部 React 组件。组件使用 useId 生成实例级 SVG 标识,并更新渐变、遮罩和图形引用。相关导入与图片导出顺序同步调整。

Changes

ErrorBlock SVG ID 参数化

Layer / File(s) Summary
内置 SVG 动态 ID
src/components/error-block/images/*.tsx
busyImagedefaultImagedisconnectedImageemptyImage 使用内部组件生成 SVG。固定标识改为基于 useId 的动态标识。
ErrorBlock 导入与图片索引整理
src/components/error-block/create-error-block.tsx, src/components/error-block/error-block.tsx, src/components/error-block/images/index.tsx
重新排列导入和图片导出顺序。公开实体和运行时逻辑未改变。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Poem

兔子挥爪改 SVG,
每个标识各自立。
渐变遮罩不相撞,
多个 ErrorBlock 同屏亮。
导入顺序也整齐。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次为 ErrorBlock 动态生成 SVG 元素 ID 的主要变更。
Linked Issues check ✅ Passed 变更为各 ErrorBlock SVG 实例生成唯一 ID,可避免多个实例之间的 ID 冲突,符合问题 #6744 的目标。
Out of Scope Changes check ✅ Passed 所有代码变更均围绕 SVG ID 动态生成展开,导入和导出顺序调整不构成无关范围变更。
✨ 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.

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. feature labels Jun 12, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 12, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/antd-mobile@7063

commit: 24066f3

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request refactors the ErrorBlock component and its default SVG images to dynamically generate unique element IDs using the useId hook, preventing ID collisions when multiple error blocks are rendered. The SVG image components are converted into functions that accept an id parameter, and the ImageRecord type is updated accordingly. The reviewer noted that the ErrorBlockProps type definition for the image prop should also be updated to include the new function signature to prevent TypeScript errors.

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.

Comment thread src/components/error-block/create-error-block.tsx Outdated
@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.30%. Comparing base (4c719ca) to head (24066f3).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
src/components/error-block/images/busy.tsx 60.00% 2 Missing ⚠️
src/components/error-block/images/disconnected.tsx 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7063      +/-   ##
==========================================
+ Coverage   92.97%   93.30%   +0.32%     
==========================================
  Files         337      337              
  Lines        7402     7434      +32     
  Branches     1887     1898      +11     
==========================================
+ Hits         6882     6936      +54     
+ Misses        484      466      -18     
+ Partials       36       32       -4     

☔ View full report in Codecov by Harness.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- 将图片组件重构为工厂函数模式
- 导出默认实例和工厂函数
- 保持原有功能不变
import React from 'react'

export const busyImage = (
export const busyImageFactory = (id: string) => (

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

感觉不需要 export,你内部封装成一个组件然后 export 出来:

https://codesandbox.io/p/sandbox/fk6l9z?file=%2Fsrc%2FApp.tsx%3A8%2C12

Passing-of-A-Dream added a commit to Passing-of-A-Dream/ant-design-mobile that referenced this pull request Aug 4, 2026
ant-design#7063 评审意见,不再导出 *ImageFactory 工厂函数与静态常量,改为
导出接收 id 的 FC 组件;createErrorBlock 以组件方式渲染并注入 useId
生成的唯一 id,避免多实例下 svg id 冲突。
ant-design#7063 评审意见,不再导出工厂函数与静态常量,改为把每张图封装成
内部自行 useId() 生成唯一 id 的组件,并 export <组件/> 元素。
createErrorBlock 无需感知 id,还原为直接渲染元素的逻辑,避免多实例
svg id 冲突。
@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Aug 4, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/components/error-block/create-error-block.tsx (1)

15-15: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

恢复 image 工厂函数兼容性。

此修改删除了 ErrorBlockProps.image 的工厂函数形式,并且不再调用该函数。现有的 image={id => <svg />} 调用会无法通过 TypeScript 检查;JavaScript 调用会将函数作为 React 子节点,导致图片不渲染。

保留工厂函数分支,并继续向它传入实例级 id。内置图片可以继续使用当前的 ReactElement 实现。

建议修改
+import useId from 'rc-util/lib/hooks/useId'
 
-  image?: string | ReactElement
+  image?: string | ReactElement | ((id: string) => ReactElement)
 
+    const id = useId()
     const image: ReactNode = props.image ?? imageRecord[props.status]
     const imageNode =
       typeof image === 'string' ? (
         <img src={image} alt='error block image' />
+      ) : typeof image === 'function' ? (
+        image(id)
       ) : (
         image
       )

Also applies to: 39-45

🤖 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 `@src/components/error-block/create-error-block.tsx` at line 15, 恢复
ErrorBlockProps.image 的工厂函数类型,支持接收实例级 id 并返回 ReactElement;在 ErrorBlock 渲染逻辑中识别
image 为函数时调用它并传入该实例 id,非函数值继续按现有 ReactElement 直接渲染,确保内置图片行为不变。
🤖 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.

Outside diff comments:
In `@src/components/error-block/create-error-block.tsx`:
- Line 15: 恢复 ErrorBlockProps.image 的工厂函数类型,支持接收实例级 id 并返回 ReactElement;在
ErrorBlock 渲染逻辑中识别 image 为函数时调用它并传入该实例 id,非函数值继续按现有 ReactElement
直接渲染,确保内置图片行为不变。

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: eee52163-07d7-4572-a24d-8259d6639c58

📥 Commits

Reviewing files that changed from the base of the PR and between e7ea39a and 232fabb.

📒 Files selected for processing (7)
  • src/components/error-block/create-error-block.tsx
  • src/components/error-block/error-block.tsx
  • src/components/error-block/images/busy.tsx
  • src/components/error-block/images/default.tsx
  • src/components/error-block/images/disconnected.tsx
  • src/components/error-block/images/empty.tsx
  • src/components/error-block/images/index.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/error-block/images/index.tsx

ant-design#7063 评审意见,内置图片已改为内部 useId 组件;但 ErrorBlock.image
作为公开 API 仍需支持 (id) => ReactElement 工厂函数,由 createErrorBlock
用 useId 生成实例级 id 传入。ImageRecord 类型同步补回工厂函数分支。
status?: ErrorBlockStatus
title?: ReactNode
image?: string | ReactElement
image?: string | ReactElement | ((id: string) => ReactElement)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

上面自带 useId 后这里就不用改了

ant-design#7063 zombieJ 评审,内置图片组件内部已自行 useId 生成唯一 id,
createErrorBlock 无需再引入 useId 或为 image 新增工厂函数分支。
还原 image 类型为 string | ReactElement、ImageRecord 为 string | ReactNode。
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Aug 4, 2026
@zombieJ
zombieJ merged commit 2529078 into ant-design:master Aug 4, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature lgtm This PR has been approved by a maintainer size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ErrorBlock显示异常

2 participants