在 safari 中更新后,svg 无法正确渲染
我正在研究 React 项目,并实现了用于图标的渐变生成器。问题是,在 chrome 上一切正常,但 safari 通常只会在第一次渲染图标,例如,如果我执行一些更新操作,例如将视图更改为移动设备或更改组件的状态,它会变成黑色。当我在图标之间切换时,它会重新生成,直到我重复该场景。
我读到 safari 的常见问题是 url 路径没有正确解析,但正如你所看到的,我已经这样做了,即使路径是硬编码的,它也不起作用。还尝试在 safari 中禁用画布渲染。
<svg
width={72}
height={26}
>
<defs>
<linearGradient id={object.id}>
{this.generateStops(object.depthColors ? object.depthColors : [])}
</linearGradient>
</defs>
<rect width={72} height={26} fill={`url(${window.location.href}#${object.id})`}/>
</svg>
我想我不会添加更多代码,因为问题不在于停止生成,它总是返回正确生成的停止。我还尝试向 svg 添加各种参数,例如 id
、viewbox
,但没有帮助。
I'm working on React project and I implemented gradient generator that is used for icons. The problem is that on chrome everything works fine, but safari renders the icon normally only first time, for example, if I do some update action like change view to mobile or change state of component it turns black. When I switch between icons it regenerates until I repeat the scenario.
I read that the common problem with safari is that url path is not resolved right, but as you can see I already done that, it's not working even when the path is hardcoded. Also tried to disable canvas rendering in safari.
<svg
width={72}
height={26}
>
<defs>
<linearGradient id={object.id}>
{this.generateStops(object.depthColors ? object.depthColors : [])}
</linearGradient>
</defs>
<rect width={72} height={26} fill={`url(${window.location.href}#${object.id})`}/>
</svg>
I think I won't add more code since the problem is not with stops generation, it always returns correctly generated stops. Also I tried to add various parameters to svg like id
, viewbox
, but it didn't help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最终做的是这样的:
以前的版本也使用唯一的id来生成渐变,但每次选择相同的渐变时它不会刷新。
What I ended up doing is this:
Previous version also used unique id's for gradient generation, but it didn't refresh every time when the same gradient is selected.
我相信我刚刚遇到了和你完全相同的问题!
我有带有线性渐变的 SVG,只有当发生一些渲染/取消渲染时(在我的例子中是模态窗口),它才会在 iOS 上变黑。 Chrome/Firefox 都很好。
详细的文章可以在此处和代码沙箱示例这里。
核心原因是 webkit 的 bug。我使用的是运行 iOS 15.4(2022 年 3 月 14 日发布)的 iPad,与提出此问题的时间相似。当我将 iPad 更新到最新版本(并更新 webkit)后,问题就消失了。
我花了 30 多个小时调试这个问题,但我不敢相信我没有考虑尝试任何其他 iOS 设备(尤其是那些完全更新到最新版本的设备)。
I believe I just ran into the exact same issue as you!
I had SVGs with linear gradient that would turn black on iOS only when some render / unrenders happened (in my case a modal window). Chrome/Firefox were fine.
A detailed write up is available here and a code sandbox example here.
The core reason was a webkit bug. I was using an iPad on iOS 15.4 (released March 14, 2022), similar time to when this question was asked. Once I updated the iPad to latest version (and thus updating webkit), the problem went away.
I spend 30+ hours debugging this issue though, I can't believe I didn't consider trying any other iOS device (especially ones that were fully updated to the latest version).