Skip to content

Commit 2402443

Browse files
cdp: add comments on setChildNodes event
Co-authored-by: Karl Seguin <[email protected]>
1 parent f884627 commit 2402443

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/cdp/domains/dom.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,14 @@ fn dispatchSetChildNodes(cmd: anytype, nodes: []*parser.Node) !void {
113113
if (plen == 0) return;
114114

115115
var i: usize = plen;
116+
// We're going to iterate in reverse order from how we added them.
117+
// This ensures that we're emitting the tree of nodes top-down.
116118
while (i > 0) {
117119
i -= 1;
118120
const node = parents.items[i];
121+
// Although our above loop won't add an already-sent node to `parents`
122+
// this can still be true because two nodes can share the same parent node
123+
// so we might have just sent the node a previous iteration of this loop
119124
if (node.set_child_nodes_event) continue;
120125

121126
node.set_child_nodes_event = true;

0 commit comments

Comments
 (0)