Bug 243341

Summary: Gradients in an SVG are affected by parent's `display: none`, when SVG is referenced through <use>
Product: WebKit Reporter: Sérgio Gomes <sergio.gomes>
Component: SVGAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: ahmad.saleem792, karlcow, sabouhallawa, webkit-bug-importer, zimmermann
Priority: P2 Keywords: BrowserCompat, InRadar, LayerBasedSVGEngine
Version: Safari 15   
Hardware: Unspecified   
OS: macOS 12   
URL: https://codepen.io/sergiomdgomes/pen/JjLOmoa?editors=1100
Attachments:
Description Flags
Safari test result
none
rendering in Safari, firefox, chrome none

Description Sérgio Gomes 2022-07-29 08:10:52 PDT
Created attachment 461295 [details]
Safari test result

Steps to reproduce the problem:
1. Visit https://codepen.io/sergiomdgomes/pen/JjLOmoa?editors=1100
2. Observe result

Expected: both circles look the same, with a black stroke and a gradient fill.
Observed: the first circle has a black stroke but a solid fill.

Problem Description:
When:
- An SVG exists inside a `display: none` parent
- That SVG contains a named gradient that gets used inside the same SVG for a fill (via `url()`)
- Another SVG references the first one via SVG <use>

Then: the gradient will not render correctly.

If you visit https://codepen.io/sergiomdgomes/pen/JjLOmoa?editors=1100 you'll see that if the referenced SVG is inside a `visibility: hidden` parent, both the stroke and the fill (which uses a named gradient) will render correctly. However, if the referenced SVG is inside a `display: none` parent, then the stroke will render correctly but the fill will not.

Firefox correctly renders the stroke and the fill in both situations.

Chromium also fails to render the gradient for a referenced SVG inside a `visibility: hidden` parent, but it applies an empty fill instead of a solid one ( Chromium bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1348561 )

Note that this is not just an issue with gradients; it also seems to be an issue for other named elements, such as masks and clip paths.
Comment 1 Karl Dubost 2022-07-31 22:35:32 PDT
Created attachment 461331 [details]
rendering in Safari, firefox, chrome

Firefox Nightly 105.0a1
Google Chrome Canary 106.0.5212.0
Safari 16.0
Comment 2 Radar WebKit Bug Importer 2022-07-31 22:36:07 PDT
<rdar://problem/97892709>