yewstack/yew · error
couldn't clone node to be cached
Error message
couldn't clone node to be cached
What it means
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.
Source
Thrown at packages/yew/src/dom_bundle/btag/mod.rs:306
static CACHED_ELEMENTS: RefCell<HashMap<String, Element>> = RefCell::new(HashMap::with_capacity(32));
}
CACHED_ELEMENTS.with(|cache| {
let mut cache = cache.borrow_mut();
let cached = cache.get(tag).map(|el| {
el.clone_node()
.expect("couldn't clone cached element")
.unchecked_into::<Element>()
});
cached.unwrap_or_else(|| {
let to_be_cached = document()
.create_element(tag)
.expect("can't create element for vtag");
cache.insert(
tag.to_string(),
to_be_cached
.clone_node()
.expect("couldn't clone node to be cached")
.unchecked_into(),
);
to_be_cached
})
})
}
}
}
}
}
impl BTag {
/// Get the key of the underlying tag
pub fn key(&self) -> Option<&Key> {
self.key.as_ref()
}
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]View on GitHub (pinned to 0e4a05472f)
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
Defensive patterns
Strategy: validation
Validate before calling
// Before relying on a custom tag in Yew, smoke-test it once in the console:
// const el = document.createElement('x-widget'); el.cloneNode();
// Both calls must succeed for Yew's create-and-cache flow to hold. Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- couldn't clone cached element
- failed to clone node.
- failed to create detached element
- invalid attribute key
- could not set property
AI-assisted analysis of yewstack/yew@0e4a05472f (2026-08-22).
Data as JSON: /api/errors/29be2073ec91eea4.
Report an issue: GitHub.