winit: Fix replacement of node in wasm

Replacing a node ends up with the following error:
Node.replaceChild: Child to be replaced is not a child of this node

It seems that Node.replaceChild is not recommended, and instead
Element.replaceWith should be preferred. Using it avoids the panic.
This commit is contained in:
traxys 2023-03-20 00:18:41 +01:00
parent d7fffaa801
commit 0231ed6f1d

View file

@ -179,13 +179,17 @@ where
.unwrap_or(None) .unwrap_or(None)
}); });
let _ = match target { match target {
Some(node) => node Some(node) => {
.replace_child(&canvas, &node) let _ = node
.expect(&format!("Could not replace #{}", node.id())), .replace_with_with_node_1(&canvas)
None => body .expect(&format!("Could not replace #{}", node.id()));
.append_child(&canvas) }
.expect("Append canvas to HTML body"), None => {
let _ = body
.append_child(&canvas)
.expect("Append canvas to HTML body");
}
}; };
} }