From 0231ed6f1d5929d84bb81e6673d3319a24f08b16 Mon Sep 17 00:00:00 2001 From: traxys Date: Mon, 20 Mar 2023 00:18:41 +0100 Subject: [PATCH] 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. --- winit/src/application.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/winit/src/application.rs b/winit/src/application.rs index b13b7214ea..31654f26ee 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -179,13 +179,17 @@ where .unwrap_or(None) }); - let _ = match target { - Some(node) => node - .replace_child(&canvas, &node) - .expect(&format!("Could not replace #{}", node.id())), - None => body - .append_child(&canvas) - .expect("Append canvas to HTML body"), + match target { + Some(node) => { + let _ = node + .replace_with_with_node_1(&canvas) + .expect(&format!("Could not replace #{}", node.id())); + } + None => { + let _ = body + .append_child(&canvas) + .expect("Append canvas to HTML body"); + } }; }