Skip to content

Commit f45da51

Browse files
committed
Add a nice comment
1 parent a4801b2 commit f45da51

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

packages/debugger/src/structure/walker.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,22 @@ function mapOwner<TEl extends object>(
391391

392392
mapChildren(owner, last_comp_id, config, mapped.children)
393393

394-
// Map html elements in DOM mode
394+
/*
395+
| Merge element tree and owner tree depth-first, using elements as positional hints
396+
|
397+
| Component A + <div> -> Component A
398+
| └─ Component B ├─ <span> └─ <div>
399+
| └─ <p> ├─ Component B
400+
| │ └─ <span>
401+
| └─ <p>
402+
| 1. Walk owner children first (depth-first)
403+
| - child elements are already part of children tree
404+
| 2. For each element in resolved tree:
405+
| - If element matches current child owner → attach preceding children to element
406+
| - If element not seen → add as new element node
407+
| - Skip already processed elements
408+
| 3. Use dual stacks to track position in both trees simultaneously
409+
*/
395410
if (config.mode === TreeWalkerMode.DOM) {
396411

397412
// elements might already be resolved when mapping components
@@ -432,8 +447,8 @@ function mapOwner<TEl extends object>(
432447
continue
433448

434449
/* Check each element and its children
435-
- not seen -> add it to the owner
436-
- a child of the current child -> add it to the owner
450+
- not seen -> add element to the owner
451+
- a child of the current child -> add child to the owner
437452
- already seen -> skip it
438453
*/
439454
while (stack_els_len > 0) {

0 commit comments

Comments
 (0)