-
Notifications
You must be signed in to change notification settings - Fork 378
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
Template in a SVG context does not have any content #744
Comments
This isn't a web components issue, but a HTML issue. As such I'd suggest filing it on whatwg/html, as here it's not going to have the right subject matter experts. I am fairly certain this is behaving per spec, but I'm not able to find it right now. SVG definitely changes the rules for all sorts of its children. Since you're not creating an actual HTML template element, but instead a SVG template element (which doesn't exist), it's definitely going to put things into the template contents document. |
What's interesting here is that, unlike div or span, adding a template inside your svg element does not close the svg element and put the template element after it in the DOM. You have to use foreignObject to embed HTML elements in SVG usually, and this gets enforced by "punishing" you by closing your SVG element and pushing the would-be-nested HTML element outside the SVG element. But for template that "punishment" isn't happening, and instead you just get a SVG template element, which behaves the same as a SVG asdf element. This effect also concurs with several other elements like html, applet, and marquee. I think I've found a relevant section of the spec but don't quite have all the pieces. |
That's because of https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inforeign "any other start tag". There's only a limited set of HTML elements that cannot be used in an SVG/MathML context. |
I think what we'd actually like is to open discussion about the potential for an It seems like a hole that we have a platform primitive for parsing and then efficiently cloning copies of inert HTML but not SVG; and more-so that we're considering adding more functionality to Is that still a Also, was template support in SVG litigated in the original |
Yeah, none of that has to do with web components; definitely worth filing on the appropriate repo. I'm not sure about the original template discussions; it'd be worth trying to look in the archives. |
There's a thread starting at https://lists.w3.org/Archives/Public/public-webapps/2012AprJun/1061.html about this, but it seems it basically got dropped since there was no good answer as to how to do it. We could introduce a mode-switch attribute perhaps, but it's unclear if that works for all use cases. |
It seems like this should be discussed in conjunction with a broader goal of supporting web components in SVG in general. |
Thanks for the speedy and numerous responses! I am okay with moving this discussion to whatwg/html if that is a more appropriate location. |
Moved the issue to whatwg/html#3553 |
In Polymer, we had an issue where our
<template is="dom-repeat">
and<template is="dom-if">
were not compatible in a SVG context (Polymer/polymer#1976). We are working on a fix in Polymer/polymer#5135, but have hit an issue with thetemplate
element in a SVG context.Please see the following reproduction case: http://jsbin.com/dufavefufu/edit?html,console,output Whenever a
template
element is included inside ansvg
element (or in general in the SVG namespace), thetemplate
element has nocontent
. Instead, thetemplate
element does havechildNodes
. Our "fix" is therefore the following:Here we detect that the
namespace
of thetemplate
we are iterating over is not the HTML namespace. Then we create a regulartemplate
in the HTML namespace and move over allchildren
of the original "broken"template
into the new template. This works, as the originalchildren
are parsed in the SVG namespace and will therefore be correctly constructed.However, we are not sure whether this is actually proper behavior. Is it expected behavior to patch up the
template
element in a different namespace in this way? In any case, our expectation was that thetemplate
inside asvg
has acontent
property which contains the DOM Nodes constructed in the correct namespace.We would like to get this behavior clarified (and potentially specced), as we could not find any mention of expected behavior in the current specification. We would like to prevent shipping code like this if it would rely on wrong behavior.
CC @sorvell @kevinpschaaf @azakus
The text was updated successfully, but these errors were encountered: