{"record":{"id":"29be2073ec91eea4","repo":"yewstack/yew","slug":"couldn-t-clone-node-to-be-cached","errorCode":null,"errorMessage":"couldn't clone node to be cached","messagePattern":"couldn't clone node to be cached","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/yew/src/dom_bundle/btag/mod.rs","lineNumber":306,"sourceCode":"                        static CACHED_ELEMENTS: RefCell<HashMap<String, Element>> = RefCell::new(HashMap::with_capacity(32));\n                    }\n\n                    CACHED_ELEMENTS.with(|cache| {\n                        let mut cache = cache.borrow_mut();\n                        let cached = cache.get(tag).map(|el| {\n                            el.clone_node()\n                                .expect(\"couldn't clone cached element\")\n                                .unchecked_into::<Element>()\n                        });\n                        cached.unwrap_or_else(|| {\n                            let to_be_cached = document()\n                                .create_element(tag)\n                                .expect(\"can't create element for vtag\");\n                            cache.insert(\n                                tag.to_string(),\n                                to_be_cached\n                                    .clone_node()\n                                    .expect(\"couldn't clone node to be cached\")\n                                    .unchecked_into(),\n                            );\n                            to_be_cached\n                        })\n                    })\n                }\n            }\n        }\n    }\n}\n\nimpl BTag {\n    /// Get the key of the underlying tag\n    pub fn key(&self) -> Option<&Key> {\n        self.key.as_ref()\n    }\n\n    #[cfg(all(target_arch = \"wasm32\", not(target_os = \"wasi\")))]","sourceCodeStart":288,"sourceCodeEnd":324,"githubUrl":"https://github.com/yewstack/yew/blob/0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3/packages/yew/src/dom_bundle/btag/mod.rs#L288-L324","documentation":"On the first render of a tag name (cache miss), Yew creates the element and immediately clones it once more to store as the template in CACHED_ELEMENTS; this expect fires when that clone fails. Like the sibling 'couldn't clone cached element' panic at line 295, cloning a freshly created element is an internal invariant - a failure points at an exotic element constructor (custom elements throwing during the extra clone) or a non-standard DOM host, not at normal application code.","triggerScenarios":"The very first render of a tag in the session (cache miss) where the constructor of the created element throws during the additional cloneNode() call - typically a registered custom element - or an embedded webview/test DOM where cloneNode can fail.","commonSituations":"Web components whose constructors assume connection or layout; unusual webviews with partial DOM implementations; Yew internal regressions. Standard tags (div, span, a) are not expected to hit this in any mainstream browser.","solutions":["Identify which tag caused the cache miss from the html!/VTag construction nearest the panic stack","Reproduce in the browser console: const el = document.createElement('<tag>'); el.cloneNode(); - if that throws, the element definition is the problem","Make custom-element constructors safe when the element is disconnected","If a plain tag reproduces it, report a Yew issue with a minimal repro and environment details"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before relying on a custom tag in Yew, smoke-test it once in the console:\n// const el = document.createElement('x-widget'); el.cloneNode();\n// Both calls must succeed for Yew's create-and-cache flow to hold.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep custom-element constructors side-effect free until the element is connected","Test first render of every custom tag in the real target browser/webview, not just Chrome","Watch Yew changelogs when upgrading if you use non-standard elements"],"tags":["dom","custom-elements","clone-node","internal-invariant"],"backgroundTag":"dom-node-clone-failed","analyzedSha":"0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3","analyzedAt":"2026-08-22T21:16:31.212Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}