Conversation
|
你好 @Alexzjt,非常感谢你的贡献. Hello, @Alexzjt, Thanks for your contribution. In order to make the code more robust, please add the corresponding unit tests, and update the docs if there are API changes. |
Summary of ChangesHello @Alexzjt, 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 addresses a critical issue where built-in SVG icons failed to display in environments with strict Content Security Policies. It introduces a robust dual-mode rendering system for icons: a primary Path mode that directly draws SVG paths for maximum CSP compatibility, and a refined Image mode that leverages Blob URLs as a secure fallback. This ensures that icons render correctly across various security configurations while also improving user interaction by fixing click area and cursor styling. Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
这个 PR 通过引入 Path 渲染模式,很好地解决了严格 CSP 环境下 SVG 图标的渲染问题,并提供了 Image 模式作为回退,方案考虑得很周全。代码重构清晰,并且增加了全面的单元测试,值得称赞。
我发现了一些可以改进的地方:
- 在
setImageAttrs方法中存在一个 bug,它会错误地给透明的点击热区(hit area)上色,导致其变得可见。 - 为了增强类型安全,
iconPathShapes数组的类型定义可以更精确,避免不安全的类型转换。 - 代码中有一处不必要的非空断言可以移除,以提升代码的可读性。
详细的修改建议请见具体的 review comments。
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## next #3319 +/- ##
==========================================
+ Coverage 75.77% 78.69% +2.92%
==========================================
Files 257 224 -33
Lines 11994 12469 +475
Branches 2464 2830 +366
==========================================
+ Hits 9088 9813 +725
+ Misses 1398 950 -448
- Partials 1508 1706 +198 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Size Change: +1.74 kB (+0.23%) Total Size: 742 kB
ℹ️ View Unchanged
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a significant improvement by implementing CSP-compatible SVG icon rendering. The new 'Path mode' directly renders SVG paths, bypassing data: URI restrictions, with a robust fallback to 'Blob URL' for more complex SVGs. The addition of comprehensive unit tests for the new rendering modes, including interaction and error handling, is commendable. The solution effectively addresses issue #3125, enhancing the library's compatibility in strict CSP environments.
👀 PR includes
✨ Feature
Enhance
🐛 Bugfix
🔧 Chore
📝 Description
背景 (Background)
在使用严格内容安全策略(CSP
img-src 'self',禁用data:协议)的环境下,S2 内置的 SVG 图标无法正常显示。Built-in SVG icons fail to load in strict CSP environments (where
data:URI scheme is blocked inimg-src).改动 (Changes)
重构图标渲染 (Refactor Icon Rendering):
d属性,使用 G 引擎的 Path 直接绘制矢量图形。此方式天然兼容 CSP。(Parse SVG paths and render directly using
G.Path. Fully CSP compliant.)<text>/<polygon>),回退使用 Blob URL 加载(比data:更安全且兼容)。(Fallback to Blob URL for complex SVGs, replacing
data:URIs.)交互优化 (Interaction Improvement):
HitArea),修复了点击范围过小和cursor: pointer样式不生效的问题。(Added transparent
HitAreaRect to ensure correct click region and cursor style in Path mode.)测试 (Tests)
(Added unit tests covering Path mode, fallback logic, and interaction. Coverage > 86%.)
🖼️ Screenshot
🔗 Related issue link
🔍 Self-Check before the merge