File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ class DetailsMenuElement extends HTMLElement {
44
44
}
45
45
46
46
const subscriptions = [ focusOnOpen ( details ) ]
47
- states . set ( this , { details, subscriptions} )
47
+ states . set ( this , { details, subscriptions, preloaded : false } )
48
48
}
49
49
50
50
disconnectedCallback ( ) {
@@ -78,6 +78,12 @@ function loadFragment(event: Event) {
78
78
const src = menu . getAttribute ( 'src' )
79
79
if ( ! src ) return
80
80
81
+ const state = states . get ( menu )
82
+ if ( ! state ) return
83
+
84
+ if ( state . preloaded ) return
85
+ state . preloaded = true
86
+
81
87
const loader = menu . querySelector ( 'include-fragment' )
82
88
if ( loader && ! loader . hasAttribute ( 'src' ) ) {
83
89
loader . addEventListener ( 'loadend' , ( ) => autofocus ( details ) )
Original file line number Diff line number Diff line change @@ -456,5 +456,21 @@ describe('details-menu element', function() {
456
456
457
457
assert . equal ( '/test' , loader . getAttribute ( 'src' ) )
458
458
} )
459
+
460
+ it ( 'does not fetch nested include-fragment' , function ( ) {
461
+ const details = document . querySelector ( 'details' )
462
+ const loader = details . querySelector ( 'include-fragment' )
463
+
464
+ details . dispatchEvent ( new CustomEvent ( 'mouseover' ) )
465
+ assert . equal ( '/test' , loader . getAttribute ( 'src' ) , 'mouse hover should trigger fetch' )
466
+
467
+ // Simulate include-fragment fetch.
468
+ const response = document . createElement ( 'include-fragment' )
469
+ loader . replaceWith ( response )
470
+
471
+ details . open = true
472
+ details . dispatchEvent ( new CustomEvent ( 'toggle' ) )
473
+ assert ( ! response . hasAttribute ( 'src' ) , 'toggle should not trigger second fetch' )
474
+ } )
459
475
} )
460
476
} )
You can’t perform that action at this time.
0 commit comments