{"record":{"id":"286f850b032201c8","repo":"leptos-rs/leptos","slug":"svg-element-creation-to-work","errorCode":null,"errorMessage":"SVG element creation to work","messagePattern":"SVG element creation to work","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"leptos/src/portal.rs","lineNumber":48,"sourceCode":"{\n    if cfg!(target_arch = \"wasm32\")\n        && Owner::current_shared_context()\n            .map(|sc| sc.is_browser())\n            .unwrap_or(true)\n    {\n        use send_wrapper::SendWrapper;\n        use wasm_bindgen::JsCast;\n\n        let mount = mount.unwrap_or_else(|| {\n            document().body().expect(\"body to exist\").unchecked_into()\n        });\n        let children = children.into_inner();\n\n        Effect::new(move |_| {\n            let container = if is_svg {\n                document()\n                    .create_element_ns(Some(\"http://www.w3.org/2000/svg\"), \"g\")\n                    .expect(\"SVG element creation to work\")\n            } else {\n                document()\n                    .create_element(\"div\")\n                    .expect(\"HTML element creation to work\")\n            };\n\n            let render_root = if use_shadow {\n                container\n                    .attach_shadow(&web_sys::ShadowRootInit::new(\n                        web_sys::ShadowRootMode::Open,\n                    ))\n                    .map(|root| root.unchecked_into())\n                    .unwrap_or(container.clone())\n            } else {\n                container.clone()\n            };\n\n            let _ = mount.append_child(&container);","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/leptos-rs/leptos/blob/32d20f6c9d517451d77beb68d88c7716823dac41/leptos/src/portal.rs#L30-L66","documentation":"When a Portal's children are SVG content, leptos creates a container element via document().create_element_ns(SVG_NAMESPACE, \"g\") and expects it to succeed. The panic means the browser environment refused to create the SVG element — essentially only possible in non-DOM environments or exotic embedders without SVG support.","triggerScenarios":"Rendering an SVG Portal in a test environment (jsdom/node without full DOM), web workers, or a webview lacking SVG namespace element creation.","commonSituations":"Unit-testing components that render Portal with SVG children; SSR leakage into client-only code paths; headless environments with incomplete DOM implementations.","solutions":["Run SVG Portal code only in a real browser environment; mock or skip in jsdom/node tests.","Ensure the code path isn't reached during SSR (gate Portal rendering on client mount).","If targeting minimal webviews, verify createElementNS with the SVG namespace is supported or switch to HTML children.","Use a fixture document with full SVG support (happy-dom/full jsdom with svg) for tests."],"exampleFix":"// before\neffect: Portal renders SVG children in jsdom test // panics\n// after\n#[cfg(feature = \"browser-tests\")]\n#[wasm_bindgen_test]\nfn portal_svg() { ... } // run in real browser via wasm-bindgen-test runner\n","handlingStrategy":"validation","validationCode":"// only run Portal-with-SVG code in a real DOM environment\nlet is_browser = cfg!(target_arch = \"wasm32\") && document().create_element_ns(Some(\"http://www.w3.org/2000/svg\"), \"g\").is_ok();\n","typeGuard":"fn svg_capable_document() -> bool {\n    document().create_element_ns(Some(\"http://www.w3.org/2000/svg\"), \"g\").is_ok()\n}\n","tryCatchPattern":null,"preventionTips":["Run SVG Portal tests in a browser (wasm-bindgen-test), not jsdom","Gate Portal rendering to client-side code paths only","Verify target webview supports SVG namespace creation"],"tags":["leptos","dom","svg","portal"],"backgroundTag":"dom-api-unavailable","analyzedSha":"32d20f6c9d517451d77beb68d88c7716823dac41","analyzedAt":"2026-09-01T18:55:42.580Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}