Summary
The client VDOM currently models mounted text nodes as elements:
priv enum INode {
// ...
Text(String, @dom.Element)
}
The underlying browser object is a DOM Text node (nodeType === 3), not an Element (nodeType === 1). This type mismatch is currently hidden by the DOM binding tracked in #132, where Document::create_text_node is declared as returning Element.
Runtime impact
Hydration exposes the mismatch directly. Once a VNode::Text matches an existing DOM text node, converting it with node.to_element().unwrap() must fail because to_element only accepts nodeType === 1.
An unchecked JS cast can make the code compile, but it leaves the VDOM with an @dom.Element value whose runtime object is still a DOM Text. Any future Element-only operation on that field can therefore fail at runtime.
Expected model
Suggested regression coverage
- Hydrate an existing matching text node and verify the same DOM node is retained.
- Hydrate mismatched text content and verify its
nodeValue is corrected in place.
- Diff a hydrated text node after hydration.
- Verify Element-only APIs are not available on the mounted text-node field.
- Regenerate and review the DOM package interface after correcting
create_text_node.
Related DOM binding issue: #132.
Summary
The client VDOM currently models mounted text nodes as elements:
The underlying browser object is a DOM
Textnode (nodeType === 3), not anElement(nodeType === 1). This type mismatch is currently hidden by the DOM binding tracked in #132, whereDocument::create_text_nodeis declared as returningElement.Runtime impact
Hydration exposes the mismatch directly. Once a
VNode::Textmatches an existing DOM text node, converting it withnode.to_element().unwrap()must fail becauseto_elementonly acceptsnodeType === 1.An unchecked JS cast can make the code compile, but it leaves the VDOM with an
@dom.Elementvalue whose runtime object is still a DOMText. Any future Element-only operation on that field can therefore fail at runtime.Expected model
Document::create_text_nodereturns the existing@dom.Textwrapper (tracked by DOM bindings expose nullable and non-Array browser values with unsound types #132).INode::Textstores@dom.Text, not@dom.Element.to_text().IsNodeoperations.@js.Valuecast is needed to claim an SSR text node.Suggested regression coverage
nodeValueis corrected in place.create_text_node.Related DOM binding issue: #132.