Allow xmlns= on <template> elements #27
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Vue components are based on HTML5 custom elements. However, HTML5
custom elements are required to be in the HTML namespace. This is not a
requirement shared by Vue components. Vue itself doesn't care about the
namespace of the elements that it is rendering (which will be determined
at runtime based on the namespace of the parent element where it's being
inserted). Therefore, it is desirable to communicate to linters and
other tools what the intended namespace of a top-level
<template>
in anSFC is.
See: https://html.spec.whatwg.org/multipage/custom-elements.html#look-up-a-custom-element-definition
Vue slots are based on HTML5 slots. However, because of the above
limitation that HTML5 custom elements are always in the HTML5 namespace,
the slots contained in them are also always in the HTML5 namespace.
Because of Vue's flexibility on this, a Vue
<slot>
may appear in anynamespace; content being rendered into a slot may end up in a different
namespace than the namespace where it was parsed. Therefore, it is
desirable to communicate to linters and other tools what the indented
namespace is of content that will be rendered in a slot.
From these two observations, it would be useful to set xmlns= on:
<template>
elements, andThe first is easy, but #2 has some concerns:
We could try checking for the slot= attribute, but that would miss cases
where we use the default slot.
in HTML5 (in the cases where this is useful, anyway), we can't set it on
normal elements anyway.
So, mostly because of the second reason, let's just say that to inform
linters about a change in namespace because of a slot, the contents must
be wrapped in a
<template>
to safely set xmlns= in a place that will beignored at runtime. So now we've revised that to allowing xmlns= on:
<template>
elements, and<template>
elements appearing in a slot.Let's just make things simple and allow it for all
<template>
elements.This means we'll be slightly too lax, and allow it on
<template v-if="...">
constructs, but I'm OK with that.
As for which namespaces to consider valid, let's limit that to HTML, SVG,
and MathML, as those are the namespaces that are allowed in an HTML5
document.