Skip to content

SVG <use> should work without specifying a fragment identifier#64752

Merged
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
karlcow:290983-svg-use-no-fragment-uri
May 20, 2026
Merged

SVG <use> should work without specifying a fragment identifier#64752
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
karlcow:290983-svg-use-no-fragment-uri

Conversation

@karlcow
Copy link
Copy Markdown
Member

@karlcow karlcow commented May 12, 2026

9ba5d25

SVG <use> should work without specifying a fragment identifier
https://bugs.webkit.org/show_bug.cgi?id=290983
rdar://148973201

Reviewed by Brent Fulgham.

Per SVG 2:

    The 'use' element can reference an entire SVG document by specifying
    an 'href' value without a fragment. Such references are taken to be
    referring to the root element of the referenced document.

    — https://svgwg.org/svg2-draft/struct.html#UseElementHrefAttribute

WebKit previously bailed out of `updateExternalDocument()` when the URL
had no fragment identifier, so the external document was never fetched
and the `<use>` rendered at 0x0. Fetch the document unconditionally and,
when the caller supplies an external document and the URL has no
fragment, resolve to the external document's root element.

The new branch in `targetElementFromIRIString()` is gated on
`externalDocument != nullptr`, so every non-<use> caller (markers,
gradients, filters, patterns, textPath, SMIL, feImage, tref, …) keeps
its exact current behaviour.

* LayoutTests/TestExpectations: Remove the expectation; the WPT
use-external-svg-resource-no-fragment-id.html passes with this patch.
* LayoutTests/platform/gtk/svg/custom/use-extern-href-expected.png: Removed.
* LayoutTests/platform/mac-tahoe-wk2-lbse-text/svg/custom/use-extern-href-expected.txt: Removed.
* LayoutTests/platform/mac-tahoe-wk2-pixel/svg/custom/use-extern-href-expected.png: Removed.
* LayoutTests/platform/mac/svg/custom/use-extern-href-expected.png: Removed.
* LayoutTests/svg/custom/use-extern-href-expected.txt: Rebaseline; the
<use y="240" href="rgb.svg"/> now renders the external root per SVG 2.
* LayoutTests/svg/custom/use-extern-href.svg: Update the comment to
cite SVG 2's clarification.
* Source/WebCore/svg/SVGURIReference.cpp:
(WebCore::SVGURIReference::targetElementFromIRIString):
* Source/WebCore/svg/SVGUseElement.cpp:
(WebCore::SVGUseElement::updateExternalDocument):

Canonical link: https://commits.webkit.org/313550@main

beba1b3

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win ⏳ 🛠 ios-apple
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ❌ 🧪 win-tests ⏳ 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe ⏳ 🛠 vision-apple
🧪 ios-wk2-wpt 🧪 api-mac-debug ✅ 🛠 gtk3-libwebrtc
🧪 api-ios ✅ 🧪 mac-wk1 ✅ 🛠 gtk
✅ 🛠 ios-safer-cpp ✅ 🧪 mac-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🛠 playstation
✅ 🧪 vision-wk2 ❌ 🧪 mac-intel-wk2
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim ❌ 🧪 mac-site-isolation
✅ 🛠 watch
✅ 🛠 watch-sim

@karlcow karlcow self-assigned this May 12, 2026
@karlcow karlcow added the SVG For bugs in the SVG implementation. label May 12, 2026
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 12, 2026
@karlcow karlcow requested review from brentfulgham, nikolaszimmermann and rwlbuis and removed request for brentfulgham and rwlbuis May 12, 2026 13:06
@nullhook
Copy link
Copy Markdown
Contributor

LGTM

Copy link
Copy Markdown
Contributor

@brentfulgham brentfulgham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, and Taher has reviewed the SVG bits. r=me

@karlcow karlcow added unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing merging-blocked Applied to prevent a change from being merged and removed merging-blocked Applied to prevent a change from being merged unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing labels May 20, 2026
@karlcow karlcow force-pushed the 290983-svg-use-no-fragment-uri branch from d30849f to beba1b3 Compare May 20, 2026 03:52
@karlcow karlcow added the safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks label May 20, 2026
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 20, 2026
@karlcow karlcow added merge-queue Applied to send a pull request to merge-queue and removed merging-blocked Applied to prevent a change from being merged safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks labels May 20, 2026
@karlcow
Copy link
Copy Markdown
Member Author

karlcow commented May 20, 2026

failures are unrelated.

https://bugs.webkit.org/show_bug.cgi?id=290983
rdar://148973201

Reviewed by Brent Fulgham.

Per SVG 2:

    The 'use' element can reference an entire SVG document by specifying
    an 'href' value without a fragment. Such references are taken to be
    referring to the root element of the referenced document.

    — https://svgwg.org/svg2-draft/struct.html#UseElementHrefAttribute

WebKit previously bailed out of `updateExternalDocument()` when the URL
had no fragment identifier, so the external document was never fetched
and the `<use>` rendered at 0x0. Fetch the document unconditionally and,
when the caller supplies an external document and the URL has no
fragment, resolve to the external document's root element.

The new branch in `targetElementFromIRIString()` is gated on
`externalDocument != nullptr`, so every non-<use> caller (markers,
gradients, filters, patterns, textPath, SMIL, feImage, tref, …) keeps
its exact current behaviour.

* LayoutTests/TestExpectations: Remove the expectation; the WPT
use-external-svg-resource-no-fragment-id.html passes with this patch.
* LayoutTests/platform/gtk/svg/custom/use-extern-href-expected.png: Removed.
* LayoutTests/platform/mac-tahoe-wk2-lbse-text/svg/custom/use-extern-href-expected.txt: Removed.
* LayoutTests/platform/mac-tahoe-wk2-pixel/svg/custom/use-extern-href-expected.png: Removed.
* LayoutTests/platform/mac/svg/custom/use-extern-href-expected.png: Removed.
* LayoutTests/svg/custom/use-extern-href-expected.txt: Rebaseline; the
<use y="240" href="rgb.svg"/> now renders the external root per SVG 2.
* LayoutTests/svg/custom/use-extern-href.svg: Update the comment to
cite SVG 2's clarification.
* Source/WebCore/svg/SVGURIReference.cpp:
(WebCore::SVGURIReference::targetElementFromIRIString):
* Source/WebCore/svg/SVGUseElement.cpp:
(WebCore::SVGUseElement::updateExternalDocument):

Canonical link: https://commits.webkit.org/313550@main
@webkit-commit-queue webkit-commit-queue force-pushed the 290983-svg-use-no-fragment-uri branch from beba1b3 to 9ba5d25 Compare May 20, 2026 06:33
@webkit-commit-queue
Copy link
Copy Markdown
Collaborator

Committed 313550@main (9ba5d25): https://commits.webkit.org/313550@main

Reviewed commits have been landed. Closing PR #64752 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 9ba5d25 into WebKit:main May 20, 2026
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label May 20, 2026
@karlcow karlcow deleted the 290983-svg-use-no-fragment-uri branch May 20, 2026 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

SVG For bugs in the SVG implementation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants