Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 部分 Svg Icon 内元素使用了 id 字段,导致多个 Icon 同时展示时有问题 #1905

Open
1 task done
nekocode opened this issue Nov 11, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@nekocode
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Which Component

Icon

Semi Version

2.46.1

Current Behavior

Chrome 下会有这个恼人的问题,复现代码:
https://codesandbox.io/s/still-morning-qzpf4f?file=/src/App.jsx

相关文章:
https://blog.patw.me/archives/1820/inline-svg-same-id-and-display-none-issue/

解决方案:
组件每个实例里的 id 都改为唯一 id,这样不同实例间就不会互相受影响了。例如使用 React 18 里的 useId,还能在 SSR 中保持 id 不变

Expected Behavior

No response

Steps To Reproduce

No response

ReproducibleCode

No response

Environment

- OS: MacOS
- browser: Chrome

Anything else?

No response

@pointhalo
Copy link
Collaborator

pointhalo commented Nov 14, 2023

@DaiQiangReal 怎么看?
svgr有过相关的讨论,但是他们也没有给明确的处理方案 gregberge/svgr#322
我们直接用 useId 不太可行,因为 < v18 的版本仍然是我们的主流用户使用的版本。
我看了下 semi-icons里有 defs 的不多,只有少数几个svg。

@nekocode
Copy link
Contributor Author

@pointhalo 会考虑把带 id 的 svg 处理一下么,尽量不依赖 id?我们项目目前打了个 patch 去掉对 id 的依赖,肉眼上好像也看不出区别
image

@pointhalo
Copy link
Collaborator

我还没详细研究过,按照我的个人理解,defs应该是相当于变量定义,use的地方相当于是引用变量。按道理不抽出声明,直接内联写,估计也ok @DaiQiangReal 确认一下

@DaiQiangReal
Copy link
Collaborator

我们改

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants