{"record":{"id":"f0faf15d33542308","repo":"yewstack/yew","slug":"can-t-create-namespaced-element-for-vtag","errorCode":null,"errorMessage":"can't create namespaced element for vtag","messagePattern":"can't create namespaced element for vtag","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/yew/src/dom_bundle/btag/mod.rs","lineNumber":270,"sourceCode":"\n        DomSlot::at(el.clone().into())\n    }\n}\n\nimpl VTag {\n    fn create_element(&self, parent: &Element) -> Element {\n        let tag = self.tag();\n        // check for an xmlns attribute. If it exists, create an element with the specified\n        // namespace\n        match self\n            .attributes\n            .iter()\n            .find(|(k, _)| *k == \"xmlns\")\n            .map(|(_, v)| v)\n        {\n            Some(xmlns) => document()\n                .create_element_ns(Some(xmlns), tag)\n                .expect(\"can't create namespaced element for vtag\"),\n            _ => {\n                if tag == \"svg\" || parent.namespace_uri().is_some_and(|ns| ns == SVG_NAMESPACE) {\n                    let namespace = Some(SVG_NAMESPACE);\n                    document()\n                        .create_element_ns(namespace, tag)\n                        .expect(\"can't create namespaced element for vtag\")\n                } else if tag == \"math\"\n                    || parent\n                        .namespace_uri()\n                        .is_some_and(|ns| ns == MATHML_NAMESPACE)\n                {\n                    let namespace = Some(MATHML_NAMESPACE);\n                    document()\n                        .create_element_ns(namespace, tag)\n                        .expect(\"can't create namespaced element for vtag\")\n                } else {\n                    thread_local! {\n                        static CACHED_ELEMENTS: RefCell<HashMap<String, Element>> = RefCell::new(HashMap::with_capacity(32));","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/yewstack/yew/blob/0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3/packages/yew/src/dom_bundle/btag/mod.rs#L252-L288","documentation":"VTag::create_element (packages/yew/src/dom_bundle/btag/mod.rs:270) honors an explicit xmlns attribute: its string value is passed straight to document().create_element_ns as the namespace, with the result unwrapped by .expect. create_element_ns throws NamespaceError for invalid namespace URIs (empty string, whitespace-containing, or otherwise malformed) and InvalidCharacterError for an invalid qualified tag name — so a bogus xmlns value on any element panics here.","triggerScenarios":"Writing html! { <mytag xmlns=\"not a uri\"> } (space in URI), xmlns=\"\" (empty namespace), or an xmlns value copied with a typo (e.g. a trailing character in the SVG/MathML URLs on a non-svg tag name the code does not special-case).","commonSituations":"Custom XML vocabularies embedded in Yew trees; copy-pasted namespace constants from docs that got mangled; user-provided namespace strings passed through configuration.","solutions":["Use the exact canonical namespace URIs (http://www.w3.org/2000/svg, http://www.w3.org/1998/Math/MathML) or a syntactically valid absolute URI for custom namespaces","Never pass an empty xmlns; omit the attribute entirely to let Yew's svg/math detection pick the namespace","Validate the xmlns value at the boundary if it comes from user/config data"],"exampleFix":"// before\nhtml! { <f:math xmlns=\"mathml\"> { children } </f:math> }\n\n// after\nhtml! { <math xmlns=\"http://www.w3.org/1998/Math/MathML\"> { children } </math> }","handlingStrategy":"validation","validationCode":"fn is_valid_namespace(uri: &str) -> bool {\n    !uri.is_empty() && !uri.chars().any(char::is_whitespace) && uri.contains(':')\n}\n\nconst SVG: &str = \"http://www.w3.org/2000/svg\";\nconst MATHML: &str = \"http://www.w3.org/1998/Math/MathML\";\n// before: <custom xmlns={user_ns}>  ->  assert is_valid_namespace(user_ns)","typeGuard":"fn known_namespace(tag: &str) -> Option<&'static str> {\n    match tag { \"svg\" => Some(\"http://www.w3.org/2000/svg\"), \"math\" => Some(\"http://www.w3.org/1998/Math/MathML\"), _ => None }\n}","tryCatchPattern":null,"preventionTips":["Use the canonical SVG/MathML namespace URIs verbatim from constants","Omit xmlns for plain svg/math tags — Yew picks the namespace automatically","Validate user- or config-supplied xmlns values before they reach the html! tree"],"tags":["rust","wasm","yew","dom","xml-namespace","runtime-panic"],"backgroundTag":"invalid-xml-namespace","analyzedSha":"0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3","analyzedAt":"2026-08-22T21:16:31.212Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}