New issue
Advanced search Search tips

Issue 616490 link

Starred by 2 users

Issue metadata

Status: Available
Owner: ----
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

SVG icons injected by innerHTML do not raise "onload" event

Reported by andreas....@gmail.com, Jun 1 2016

Issue description

Chrome Version       : 49.0.2623.75 (Official Build) m (32-bit)
URLs (if applicable) :
Other browsers tested:
  Add OK or FAIL, along with the version, after other browsers where you
have tested this issue:
     Safari: FAIL Safari 9.11 (MacOS 10.11.5)
    Firefox: OK Firefox 45 (Windows 7)
         IE: OK IE 11 Win (Windows 7)

What steps will reproduce the problem?
(1) Load attached HTML file "the.html" in Chrome browser 
(2) See that the SVG loaded initially in the HTML raises onload event
(3) See that the SVG injected by "innerHTML" does not raise onload event

What is the expected result?
The SVG injected by "innerHTML" schould raise "onload" event after being injected like an IMG is doing it.

What happens instead?
No event is raised

Please provide any additional information below. Attach a screenshot if
possible.

See here the HTML example as plain text

<!DOCTYPE html>
<html>
<head>
	<script>
		function inject() {
			document.getElementById("Inject").innerHTML = '<svg onload="logMessage(\'Loaded Injected SVG\')" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 512" width="20" height="20"><path d="M499 183l-141 121 78 208-182-124-181 124 73-207-146-122h185l69-186 62 186h183zm-134 236l-48-130 87-75h-113l-39-116-43 116h-115l91 76-46 129 113-77z"/></svg>';
		}
		
		function logMessage(sMessage) {
			document.getElementById("MessageLog").innerHTML += sMessage + "<br/>";
		}
	</script>
</head>
<body onload="inject()">
		
	<svg onload="logMessage('Loaded Initial SVG')" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 512" width="20" height="20"><path d="M499 183l-141 121 78 208-182-124-181 124 73-207-146-122h185l69-186 62 186h183zm-134 236l-48-130 87-75h-113l-39-116-43 116h-115l91 76-46 129 113-77z"/></svg>

	<div id="Inject">
	</div>
	
	<div id="MessageLog">
	</div>

</body>
</html>
 
the.html
971 bytes View Download

Comment 1 by f...@opera.com, Jun 2 2016

Components: Blink>SVG
Per my reading of SVG2 we should not be dispatching any events in this case:

"The load event is dispatched only to structurally external elements and to the Window, when the corresponding external resources have finished loading."

SVG 1.1 had a more vague formulation which I believe was something like: "Send SVGLoad to an element as soon as it have been parsed." (and no browser implemented it like that IIRC). This is likely why you see other browsers dispatching 'load' (and/or some alias thereof) in this case.

This was discussed a few years back:

https://www.w3.org/2013/11/15-svg-minutes.html#item07

I'd suggest you raise this issue on the spec (at https://github.com/w3c/svgwg/) for clarification. Thank you.
Hi,

thanks for the insight. 

I)
a)The SVG embedded in the initial HTML raises an onload event.
b)The SVG injected by innerHTML does not.
Both do not refer to external resources. 

I would expect an symmetric behavior. From you explanation both should not raise an onload event, right?
If you are not able to remove the onload notification for a) because of compatibility reasons, from my point of view it would make sense to introduce it in b)

II)
Actually the testcase was a bit simplified. Our actual usecase is to load an SVG from a symbol library in this format: 

<svg onload="notifyOnload(this)"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="./svgSymbolLib.svg#star"></use></svg>

which is an external resource and we need to get notified when it is loaded.

Any suggestions how to achieve that?

Many thanks for the fast processing.

Comment 3 by f...@opera.com, Jun 2 2016

Status: Available (was: Unconfirmed)
I looked at how this is currently handled in Blink, and realized that it likely was intended to dispatch a 'load' for this case. Or rather there are some oddities like:

document.body.innerHTML = '<svg onload=alert("bar")><svg onload=alert("foo")></svg></svg>';

Which will alert "foo" but not "bar".

For your case with <use>, we will dispatch 'load' for the <use> element in this case (since it is "structurally external"). Firefox for instance will not though (only does that for <svg>.) Another thing to be aware of with <svg onload> is that'll be dispatched when the end tag (</svg>) has been parsed, so it doesn't really make any guarantees as to the readiness of the subtree rooted at the <svg>.
Our use case is to inline an external SVG symbol libray in the document on demand to achieve some better CSS theming behavior.
Actually <use>.onload works perfect for this scenario. Thanks for that hint.

As you described Firefox is propagating the event only for the <svg> while IE raises it additionally for <use> as well.
Safari seems to propagate the “load” on <use> element twice (parsed and external resource loaded?).

Project Member

Comment 5 by sheriffbot@chromium.org, Jun 5 2017

Labels: Hotlist-Recharge-Cold
Status: Untriaged (was: Available)
This issue has been Available for over a year. If it's no longer important or seems unlikely to be fixed, please consider closing it out. If it is important, please re-triage the issue.

Sorry for the inconvenience if the bug really should have been left as Available. If you change it back, also remove the "Hotlist-Recharge-Cold" label.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot

Comment 6 by f...@opera.com, Jun 5 2017

Labels: -Hotlist-Recharge-Cold
Status: Available (was: Untriaged)
Project Member

Comment 7 by sheriffbot@chromium.org, Jun 5 2018

Labels: Hotlist-Recharge-Cold
Status: Untriaged (was: Available)
This issue has been Available for over a year. If it's no longer important or seems unlikely to be fixed, please consider closing it out. If it is important, please re-triage the issue.

Sorry for the inconvenience if the bug really should have been left as Available.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
Status: Available (was: Untriaged)

Sign in to add a comment