Skip to content

SVG attributes namespaces are not applied inside components #6169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
CobraCalle opened this issue Dec 29, 2018 · 4 comments
Closed

SVG attributes namespaces are not applied inside components #6169

CobraCalle opened this issue Dec 29, 2018 · 4 comments
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-svg ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved
Milestone

Comments

@CobraCalle
Copy link

CobraCalle commented Dec 29, 2018

I want to inline an image in a svg and provide the image as data url. When the data url is generated through blazor the image will not be loaded

Steps to reproduce the behavior:

<svg width="100%" height="100%" viewBox="0 0 480 360" color="red" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
			<svg >
				<image xlink:href="@("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAB3RJTUUH2AQPDQ0laSi7LQAAAAlwSFlzAAALEgAACxIB0t1+/AAAAARnQU1BAACxjwv8YQUAAALdSURBVHjabVPvS1NRGH7OvfPeuU03M9TEAsmVKIz+gBA0w4SKzWmyRSkk7IPf9U8JKvowwiACi74GQj9QcPghlXKacxk2U8Fwbvfuxz09VzYx6LDDOTvnfZ73ed73XBWVcRMYagcWrgLbG8AK/jNCwEgHkOgCvn87GzMAjEacTuv91JR85PHIIWCMx+Is+D4QiWma9bqvT8Z0XY4CD+1z1c58zuV6NTk9LXx1degOBLC5tBTsKBZTTPHFDiJbxKfrM7f7+4ViWbjU1IRfmUyo3bKS4gZwODU56W3ioXl0BKtYRCmfx2w8joxhjGtA4bymzQz29sI0TRSOj1FiTDGbxezGRkm9AmxuLi8Pd/v9ArwoM8BRKqHr8mXsJJNBl8MRDvX0QJTLkLkcLJILxixubSEr5cSJzzAlNjJLNByGJgREoQAHAbYie69wze/vw+BaoIoESXaA2HPgmWoTfGVF/eVyMr22Fu5ua4OTPh1Uo+7uQqTTUCjXVqWSdJEqdqWMPSWYUEutVnnFJmFR0qlUuNPng0qJGjPW1tRAdzhgUcnHw0NsW1bscQVs45SzrbL/KMyUW12FztWj66h3OuHRNNTYfZUStYDJraxiThXYrWoQYmaArWz2euEmyM3sbpLoqgqN60XGZfL54DUg9bnS4hOCCH/1BPfV1qLR5YKTkll9HNG7Qt91bjcKVFTmWSvjf5pmMECSBZKoQeCeD3h5XdeFl1lqFOXEc57Feru3hxX69lMJeGaQrMj7ZnYqUygE+QTWxV16uqWqWgNl2l5t3wq9zhH427LGncBBqxDv7rS0oEiiYxbTnjnDwJtcrqR28iH9kTJ8wc7MWWQL51j9A4JZ7fg8s9BzYiufj7ZRhcl7gwSfqDALPFDXgGVKSR1IGWqitHkycz/OPser1WbB1gNSJn4YRrSFMR/4Eg+lHHsCvDht4TAQHeG7j5x8eP9+iZUhJoBBTpMzWj38C2dRTZc15mQUAAAAAElFTkSuQmCC")" width="16" height="16" />
			</svg>
</svg>

Expected behavior

As you can see: In this sample the dat url is provided through blazor (xlink:href="@("data:image/png;base64,")")... the image will not be shown… change is to xlink:href="data:image/png;base64,")... and it will work

@Eilon Eilon added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jan 2, 2019
@danroth27 danroth27 added the area-blazor Includes: Blazor, Razor Components label Feb 6, 2019
@mkArtakMSFT
Copy link
Member

Thanks for contacting us, @CobraCalle.
It's not clear what do you try to do. Why do you wrap that data in @?
We treat that BASE64 encoded content as C#. If you want it to be treated as text, you can at least define as text.
Anyway, it's not clear what you want to achieve here. Would be great to get more details.

@danroth27
Copy link
Member

We think you're running into an encoding issue. We should try using MarkupString in this case.

@SteveSandersonMS
Copy link
Member

I tracked this down. The issue is not to do with encoding. It's purely to do with how the JS-side code applies the attribute.

For normal DOM elements, you can always use setAttribute to assign the attribute value. But attributes on SVG elements are special, in that they can have a namespace too, such as with xlink:href. For this example to work, we would need to be assigning the attribute via:

element.setAttributeNS('http://www.w3.org/1999/xlink', 'href', attributeValueString);

To implement this,

  • We should change BrowserRenderer.ts so that when it's about to call toDomElement.setAttribute, it checks if toDomElement has the SVG namespace. If so, then it should check whether the attribute name includes a namespace.
  • I'm not yet sure how we should know what the fully-qualified namespace is. That is, how we transform xlink in this example to http://www.w3.org/1999/xlink. Perhaps there is a small set that we can hard-code, but it doesn't appear that we can derive that knowledge programmatically at runtime.

As a further alternative, we may note that the entire xlink namespace has been deprecated since SVG 2 and should no longer be used anyway. Browsers are free to drop support for it, and some may already have done. Developers should just use href instead of xlink:href.

Does anyone know of scenarios in SVG where it's still necessary to use setAttributeNS? We will most likely only implement something for this if there are known scenarios where it's needed, or if this becomes a much more commonly-requested item for some reason.

Moving to "backlog" so we can reconsider when/if we have more information.

@SteveSandersonMS SteveSandersonMS changed the title Image data von inlining in svg cannot be loaded through balzor SVG attributes namespaces are not applied inside components Apr 15, 2019
@SteveSandersonMS SteveSandersonMS removed their assignment Apr 15, 2019
@mkArtakMSFT mkArtakMSFT removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels May 9, 2019
@mkArtakMSFT mkArtakMSFT removed the area-blazor Includes: Blazor, Razor Components label Oct 23, 2019
@javiercn javiercn added the area-blazor Includes: Blazor, Razor Components label Oct 24, 2019
@mkArtakMSFT mkArtakMSFT added the enhancement This issue represents an ask for new feature or an enhancement to an existing one label Jan 10, 2020
@mkArtakMSFT mkArtakMSFT modified the milestones: Backlog, 5.0.0-preview2 Jan 23, 2020
@mkArtakMSFT
Copy link
Member

Closing as we will be tackling this as part of #18271

@mkArtakMSFT mkArtakMSFT added the ✔️ Resolution: Duplicate Resolved as a duplicate of another issue label May 14, 2020
@ghost ghost added the Status: Resolved label May 14, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jun 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-svg ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved
Projects
None yet
Development

No branches or pull requests

6 participants