Add SVG `<script>`, `<style>`, and `<title>` to set of ambiguous elements — closes #349

This commit is contained in:
Greg Johnston 2023-01-21 07:23:32 -05:00
parent a49dfd3f8e
commit 89ee88d75e
2 changed files with 12 additions and 10 deletions

View File

@ -982,14 +982,19 @@ macro_rules! generate_html_tags {
#[cfg(all(debug_assertions, target_arch = "wasm32", feature = "web"))]
fn warn_on_ambiguous_a(parent: &web_sys::Element, child: &View) {
if let View::Element(el) = &child {
if el.name == "a" {
if el.name == "a"
|| el.name == "script"
|| el.name == "style"
|| el.name == "title"
{
if parent.namespace_uri() != el.element.namespace_uri() {
crate::warn!(
"Warning: you are appending an SVG <a/> to an HTML element, or an \
HTML <a/> to an SVG. Typically, this occurs when you create an \
<a/> with the `view` macro and append it to an SVG, but the \
framework assumed it was HTML when you created it. To specify that \
it is an SVG <a/>, use <svg::a/> in the view macro."
"Warning: you are appending an SVG element to an HTML element, or \
an HTML element to an SVG. Typically, this occurs when you create \
an <a/> or <script/> with the `view` macro and append it to an \
SVG, but the framework assumed it was HTML when you created it. To \
specify that it is an SVG element, use <svg::{tag name}/> in the \
view macro."
)
}
}

View File

@ -1033,16 +1033,13 @@ fn is_svg_element(tag: &str) -> bool {
| "polyline"
| "radialGradient"
| "rect"
| "script"
| "set"
| "stop"
| "style"
| "svg"
| "switch"
| "symbol"
| "text"
| "textPath"
| "title"
| "tspan"
| "use"
| "use_"
@ -1088,7 +1085,7 @@ fn is_math_ml_element(tag: &str) -> bool {
}
fn is_ambiguous_element(tag: &str) -> bool {
matches!(tag, "a")
tag == "a" || tag == "script"
}
fn parse_event(event_name: &str) -> (&str, bool) {