RESOLVED FIXED244025
`:visited` link color does not propagate to SVG through `currentColor`
https://bugs.webkit.org/show_bug.cgi?id=244025
Summary `:visited` link color does not propagate to SVG through `currentColor`
Masataka Yakura
Reported 2022-08-17 01:46:50 PDT
Created attachment 461688 [details] test case - `:visited` + `fill="currentColor"` Steps to reproduce: 1. open attachment or go to https://myakura.github.io/test--visited-currentcolor-svg/ 2. look at the test case Expected result: There is a green square. Actual result: There is a red square, in Safari (15.6) and Safari TP (151). It is green in Firefox and Chrome. Additional comments: People build customizable icon system by utilizing `fill="currentColor"` set on inline SVGs. * https://css-tricks.com/cascading-svg-fill-color/ * https://mayashavin.com/articles/svg-icons-currentcolor * https://gomakethings.com/currentcolor-and-svgs/ However, WebKit doesn't propagate colors set on `:visited` elements. So if such icons are placed inside links, they won't look as expected. https://stackoverflow.com/questions/68116594/safari-not-showing-visited-color-for-svg-icon-that-is-inside-an-anchor-tag
Attachments
test case - `:visited` + `fill="currentColor"` (921 bytes, text/html)
2022-08-17 01:46 PDT, Masataka Yakura
no flags
rendering in safari, firefox, chrome (624.78 KB, image/png)
2025-08-18 17:44 PDT, Karl Dubost
no flags
testcase with impact on getComputedStyle color (2.27 KB, text/html)
2025-11-27 17:29 PST, Karl Dubost
no flags
rendering in safari, firefox, chrome for visited color test with getCS (155.00 KB, image/png)
2025-11-27 17:31 PST, Karl Dubost
no flags
Masataka Yakura
Comment 1 2022-08-17 01:51:53 PDT
Radar WebKit Bug Importer
Comment 2 2022-08-17 04:53:00 PDT
Karl Dubost
Comment 3 2025-08-18 17:44:15 PDT
Created attachment 476445 [details] rendering in safari, firefox, chrome Safari Technology Preview 26.0 20622.1.20.1 (125) Firefox Nightly 143.0a1 14325.8.14 Google Chrome Canary 141.0.7364.1 7364.1
Karl Dubost
Comment 4 2025-08-18 17:45:26 PDT
Both Firefox and Safari shows a red square.
Ahmad Saleem
Comment 5 2025-11-26 10:12:21 PST
It is quite easy to fix: https://searchfox.org/wubkat/rev/7da001264416843beaa28b96f6f7f859950ce82d/Source/WebCore/rendering/svg/legacy/LegacyRenderSVGResource.cpp#80 ``` // For `currentcolor`, 'color' already contains the 'visitedColor'. if (auto visitedPaintColor = visitedPaint.tryColor(); visitedPaintColor && !visitedPaintColor->isCurrentColor()) { if (auto visitedColor = style.colorResolvingCurrentColor(*visitedPaintColor); visitedColor.isValid()) color = visitedColor.colorWithAlpha(color.alphaAsFloat()); } ``` Change to: ``` ``` if (auto visitedPaintColor = visitedPaint.tryColor()) { if (visitedPaintColor->isCurrentColor()) { color = style.visitedLinkColor(); } else { if (auto visitedColor = style.colorResolvingCurrentColor(*visitedPaintColor); visitedColor.isValid()) color = visitedColor.colorWithAlpha(color.alphaAsFloat()); } } ``` It progresses attached test case.
Ahmad Saleem
Comment 6 2025-11-26 19:18:04 PST
Karl Dubost
Comment 7 2025-11-27 17:29:58 PST
Created attachment 477542 [details] testcase with impact on getComputedStyle color This is a testcase to make sure the colors are not leaked through getComputedStyle.
Karl Dubost
Comment 8 2025-11-27 17:31:49 PST
Created attachment 477543 [details] rendering in safari, firefox, chrome for visited color test with getCS if my test is right the colors are currently not being leaked inside Chrome. Firefox doesn't apply the :visited color to the rect Safari too hence this bug.
Ahmad Saleem
Comment 9 2026-01-10 17:51:08 PST
@Karl - I think getComputedStyle might not work due to https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Selectors/Privacy_and_:visited ``` To preserve users' privacy, browsers lie to web applications under certain circumstances: The window.getComputedStyle method and similar functions, such as element.querySelector, always return values indicating that a user has never visited any of the links on a page. ```
Ahmad Saleem
Comment 10 2026-01-10 17:58:28 PST
One second thought, I found this - color-mix-currentcolor-visited-getcomputedstyle.html WPT test: WPT Test case - https://wpt.fyi/results/css/css-color/color-mix-currentcolor-visited-getcomputedstyle.html?label=experimental&label=master&aligned I can easily convert this for SVG case and add it as well with my PR - if my PR regresses this then we will not merge it else it would be good to get another test coverage plus fix this bug. Will update my PR.
EWS
Comment 11 2026-01-28 20:06:37 PST
Committed 306387@main (8be100449e65): <https://commits.webkit.org/306387@main> Reviewed commits have been landed. Closing PR #54500 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.