File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -13,8 +13,29 @@ function generateAncestry(node) {
13
13
nodeName !== 'body' &&
14
14
parent . children . length > 1
15
15
) {
16
- const index = Array . prototype . indexOf . call ( parent . children , node ) + 1 ;
17
- nthChild = `:nth-child(${ index } )` ;
16
+ let index = 0 ;
17
+ if ( parent . nodeName === 'BODY' ) {
18
+ let count = 0 ;
19
+ // Single pass over siblings: count valid children & locate node position.
20
+ for (
21
+ let sib = parent . firstElementChild ;
22
+ sib ;
23
+ sib = sib . nextElementSibling
24
+ ) {
25
+ if ( sib . hasAttribute ( 'data-percy-injected' ) ) {
26
+ continue ;
27
+ }
28
+ count ++ ;
29
+ if ( sib === node ) {
30
+ index = count ;
31
+ break ;
32
+ }
33
+ }
34
+ nthChild = count > 1 ? `:nth-child(${ index } )` : '' ;
35
+ } else {
36
+ index = Array . prototype . indexOf . call ( parent . children , node ) + 1 ;
37
+ nthChild = `:nth-child(${ index } )` ;
38
+ }
18
39
}
19
40
20
41
return generateAncestry ( parent ) + ' > ' + nodeName + nthChild ;
You can’t perform that action at this time.
0 commit comments