File tree 2 files changed +25
-0
lines changed
2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,8 @@ export default class IncludeFragmentElement extends HTMLElement {
50
50
return this . #getData( )
51
51
}
52
52
53
+ #busy = false
54
+
53
55
attributeChangedCallback ( attribute : string , oldVal : string | null ) : void {
54
56
if ( attribute === 'src' ) {
55
57
// Source changed after attached so replace element.
@@ -132,6 +134,9 @@ export default class IncludeFragmentElement extends HTMLElement {
132
134
)
133
135
134
136
#handleData( ) : Promise < void > {
137
+ if ( this . #busy) return Promise . resolve ( )
138
+ this . #busy = true
139
+
135
140
this . #observer. unobserve ( this )
136
141
return this . #getData( ) . then (
137
142
( html : string ) => {
Original file line number Diff line number Diff line change @@ -587,4 +587,24 @@ suite('include-fragment-element', function () {
587
587
assert . equal ( document . querySelector ( '#replaced' ) . textContent , 'hello' )
588
588
} )
589
589
} )
590
+
591
+ test ( 'include-fragment-replaced is only called once' , function ( ) {
592
+ const div = document . createElement ( 'div' )
593
+ div . hidden = true
594
+ document . body . append ( div )
595
+
596
+ div . innerHTML = `<include-fragment src="/hello">loading</include-fragment>`
597
+ div . firstChild . addEventListener ( 'include-fragment-replaced' , ( ) => ( loadCount += 1 ) )
598
+
599
+ let loadCount = 0
600
+ setTimeout ( ( ) => {
601
+ div . hidden = false
602
+ } , 0 )
603
+
604
+ return when ( div . firstChild , 'include-fragment-replaced' ) . then ( ( ) => {
605
+ assert . equal ( loadCount , 1 , 'Load occured too many times' )
606
+ assert . equal ( document . querySelector ( 'include-fragment' ) , null )
607
+ assert . equal ( document . querySelector ( '#replaced' ) . textContent , 'hello' )
608
+ } )
609
+ } )
590
610
} )
You can’t perform that action at this time.
0 commit comments