diff --git a/src/browser/parser/Parser.zig b/src/browser/parser/Parser.zig index 2cb2acaa..08adfb47 100644 --- a/src/browser/parser/Parser.zig +++ b/src/browser/parser/Parser.zig @@ -421,7 +421,16 @@ fn appendBeforeSiblingCallback(ctx: *anyopaque, sibling_ref: *anyopaque, node_or fn _appendBeforeSiblingCallback(self: *Parser, sibling: *Node, node_or_text: h5e.NodeOrText) !void { const parent = sibling.parentNode() orelse return error.NoParent; const node: *Node = switch (node_or_text.toUnion()) { - .node => |cpn| getNode(cpn), + .node => |cpn| blk: { + const child = getNode(cpn); + if (child._parent) |previous_parent| { + // A custom element constructor may have inserted the node into the + // DOM before the parser officially places it (e.g. via foster + // parenting). Detach it first so insertNodeRelative's assertion holds. + self.page.removeNode(previous_parent, child, .{ .will_be_reconnected = parent.isConnected() }); + } + break :blk child; + }, .text => |txt| try self.page.createTextNode(txt), }; try self.page.insertNodeRelative(parent, node, .{ .before = sibling }, .{}); diff --git a/src/browser/tests/custom_elements/registry.html b/src/browser/tests/custom_elements/registry.html index 064aa9f9..2d0f5dc0 100644 --- a/src/browser/tests/custom_elements/registry.html +++ b/src/browser/tests/custom_elements/registry.html @@ -119,3 +119,33 @@ } + diff --git a/src/http/Client.zig b/src/http/Client.zig index fde007c6..1a38ef9e 100644 --- a/src/http/Client.zig +++ b/src/http/Client.zig @@ -1417,7 +1417,7 @@ pub const Transfer = struct { header_len = buf_len - 1; } - const header = buffer[0 .. header_len]; + const header = buffer[0..header_len]; // We need to parse the first line headers for each request b/c curl's // CURLINFO_RESPONSE_CODE returns the status code of the final request.