Skip to content

feat(ui-svg-images): add allowUseElement prop to InlineSVG - #2661

Open
joyenjoyer wants to merge 1 commit into
masterfrom
INSTUI-5117-allow-use-elements
Open

feat(ui-svg-images): add allowUseElement prop to InlineSVG#2661
joyenjoyer wants to merge 1 commit into
masterfrom
INSTUI-5117-allow-use-elements

Conversation

@joyenjoyer

@joyenjoyer joyenjoyer commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add opt-in allowUseElement prop to InlineSVG, permitting <use> elements restricted to same-document fragment refs (#id). Default is unchanged, <use> is still stripped.
  • Enforce the fragment-only rule with an afterSanitizeAttributes hook.
  • Document the prop with a live before/after example in the README.

Test Plan

  • On the docs site, open InlineSVG → "Using SVG sprite sheets with <use> elements": the first SVG should show three colored circles, the second (no prop) should be blank.

Fixes INSTUI-5117

🤖 Generated with Claude Code

Allow <use> elements restricted to same-document fragment references, so SVG sprite sheets
render. External URLs, data: and javascript: schemes stay blocked. The default behaviour is
unchanged, with <use> still stripped.
@joyenjoyer joyenjoyer self-assigned this Jul 27, 2026
@joyenjoyer
joyenjoyer requested a review from balzss July 27, 2026 16:54
@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://instructure.design/pr-preview/pr-2661/

Built to branch gh-pages at 2026-07-27 16:57 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

github-actions Bot pushed a commit that referenced this pull request Jul 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Visual regression report

⚠️ Changes detected.

Status Count
Unchanged 0
Changed 1
New 96
Removed 32

📊 View full report

Diff images (33)

alert.png — baseline no longer produced

avatar.png — baseline no longer produced

badge.png — baseline no longer produced

billboard.png — baseline no longer produced

breadcrumb.png — baseline no longer produced

button-and-derivatives.png — baseline no longer produced

byline.png — baseline no longer produced

calendar.png — baseline no longer produced

checkbox.png — baseline no longer produced

checkboxgroup.png — baseline no longer produced

colorpicker.png — baseline no longer produced

contextview.png — baseline no longer produced

custom-and-lucide-icons.png — baseline no longer produced

dateinput-dateinput2.png — baseline no longer produced

datetimeinput.png — baseline no longer produced

diff-demo.png — 6324 pixels differ

drilldown.png — baseline no longer produced

filedrop.png — baseline no longer produced

form-errors.png — baseline no longer produced

heading.png — baseline no longer produced

img.png — baseline no longer produced

link.png — baseline no longer produced

menu.png — baseline no longer produced

metric-pill-tag-timeselect-text.png — baseline no longer produced

options.png — baseline no longer produced

pagination.png — baseline no longer produced

progressbar.png — baseline no longer produced

select-simpleselect.png — baseline no longer produced

table.png — baseline no longer produced

tabs.png — baseline no longer produced

tooltip.png — baseline no longer produced

treebrowser.png — baseline no longer produced

view.png — baseline no longer produced

Baselines come from the visual-baselines branch. They refresh on every merge to master.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds an opt-in allowUseElement prop to InlineSVG (in ui-svg-images) so callers can preserve SVG <use> elements while restricting href / xlink:href to same-document fragment references (#id). This supports sprite-sheet style SVG usage while keeping the default behavior (stripping <use>) unchanged.

Changes:

  • Extend sanitizeSvg to accept an allowUseElement option that conditionally permits <use> plus href/xlink:href, and adds a fragment-only enforcement hook.
  • Add allowUseElement to InlineSVG props and plumb it through to sanitization.
  • Document the new prop in the InlineSVG README and add unit tests covering default stripping and opt-in behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/ui-svg-images/src/InlineSVG/sanitizeSvg.ts Adds allowUseElement sanitization option and fragment-only enforcement hook for <use> references.
packages/ui-svg-images/src/InlineSVG/README.md Documents allowUseElement with a live sprite-sheet <use> example.
packages/ui-svg-images/src/InlineSVG/props.ts Adds the new allowUseElement prop and includes it in allowedProps.
packages/ui-svg-images/src/InlineSVG/index.tsx Wires allowUseElement into the sanitizeSvg call path.
packages/ui-svg-images/src/InlineSVG/tests/sanitizeSvg.test.tsx Adds coverage for <use> stripping by default and fragment-only behavior when enabled.
packages/ui-svg-images/src/InlineSVG/tests/InlineSVG.test.tsx Adds integration coverage ensuring <use> rendering only occurs when the prop is set.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +66 to +69
if (options?.allowUseElement) {
config.ADD_TAGS = ['use']
config.ADD_ATTR = ['href', 'xlink:href']
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants