{"record":{"id":"dbeb92cb24ae3687","repo":"leptos-rs/leptos","slug":"html-element-creation-to-work","errorCode":null,"errorMessage":"HTML element creation to work","messagePattern":"HTML element creation to work","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"leptos/src/portal.rs","lineNumber":52,"sourceCode":"            .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);\n            let handle = SendWrapper::new((\n                mount::mount_to(render_root.unchecked_into(), {\n                    let children = Arc::clone(&children);\n                    move || untrack(|| children())","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/leptos-rs/leptos/blob/32d20f6c9d517451d77beb68d88c7716823dac41/leptos/src/portal.rs#L34-L70","documentation":"The non-SVG branch of Portal creates its container with document().create_element(\"div\") and expects success. Like the SVG case, this fails only when the runtime environment cannot create HTML elements — no real document attached (workers, tests without DOM).","triggerScenarios":"Rendering a Portal (default HTML children) inside a web worker, SSR code path, or test harness where document().create_element returns Err.","commonSituations":"Calling Portal-rendering components from server code; wasm tests without a DOM; exotic webviews without DOM support.","solutions":["Ensure Portal rendering only runs client-side in a browser with a live document.","In tests use an environment that supports createElement (jsdom document with window, or a browser test runner).","Gate the component behind a client-only boundary (CreateEffect/mount callback rather than SSR render).","If SSR is required, render placeholder markup instead of Portal on the server."],"exampleFix":"// before\n#[test]\nfn renders_portal() { /* jsdom-less: create_element fails */ }\n// after\n#[wasm_bindgen_test]\nfn renders_portal() { /* browser test runner: real document */ }\n","handlingStrategy":"validation","validationCode":"if document().create_element(\"div\").is_err() {\n    // DOM unavailable: skip Portal rendering\n    return;\n}\n","typeGuard":"fn dom_available() -> bool {\n    document().create_element(\"div\").is_ok()\n}\n","tryCatchPattern":null,"preventionTips":["Only render Portal in a browser with a live document","Use browser-based test runners for DOM components","Render server-side placeholders instead of Portal during SSR"],"tags":["leptos","dom","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"}