From 2402443dcc8a1f716c7fdb97e19ccae3baa1e4e8 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 5 May 2025 08:48:04 +0200 Subject: [PATCH] cdp: add comments on setChildNodes event Co-authored-by: Karl Seguin --- src/cdp/domains/dom.zig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cdp/domains/dom.zig b/src/cdp/domains/dom.zig index e17aa94e..c37f59cb 100644 --- a/src/cdp/domains/dom.zig +++ b/src/cdp/domains/dom.zig @@ -113,9 +113,14 @@ fn dispatchSetChildNodes(cmd: anytype, nodes: []*parser.Node) !void { if (plen == 0) return; var i: usize = plen; + // We're going to iterate in reverse order from how we added them. + // This ensures that we're emitting the tree of nodes top-down. while (i > 0) { i -= 1; const node = parents.items[i]; + // Although our above loop won't add an already-sent node to `parents` + // this can still be true because two nodes can share the same parent node + // so we might have just sent the node a previous iteration of this loop if (node.set_child_nodes_event) continue; node.set_child_nodes_event = true;