File tree 2 files changed +16
-1
lines changed
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ export default class IncludeFragmentElement extends HTMLElement {
111
111
attributeChangedCallback ( attribute : string , oldVal :string | null ) : void {
112
112
if ( attribute === 'src' ) {
113
113
// Source changed after attached so replace element.
114
- if ( this . isConnected ) {
114
+ if ( this . isConnected && this . loading === 'eager' ) {
115
115
handleData ( this )
116
116
}
117
117
} else if ( attribute === 'loading' ) {
Original file line number Diff line number Diff line change @@ -466,6 +466,21 @@ suite('include-fragment-element', function() {
466
466
] )
467
467
} )
468
468
469
+ test ( 'loading=lazy does not load when src is changed' , function ( ) {
470
+ const div = document . createElement ( 'div' )
471
+ div . innerHTML = '<include-fragment loading="lazy" src="">loading</include-fragment>'
472
+ div . hidden = true
473
+ document . body . appendChild ( div )
474
+ div . firstChild . src = '/hello'
475
+ return Promise . race ( [
476
+ when ( div . firstChild , 'load' ) . then ( ( ) => {
477
+ throw new Error ( '<include-fragment loading=lazy> loaded too early' )
478
+ } ) ,
479
+ new Promise ( resolve => setTimeout ( resolve , 100 ) )
480
+ ] )
481
+ } )
482
+
483
+
469
484
test ( 'loading=lazy loads as soon as element visible on page' , function ( ) {
470
485
const div = document . createElement ( 'div' )
471
486
div . innerHTML = '<include-fragment loading="lazy" src="/hello">loading</include-fragment>'
You can’t perform that action at this time.
0 commit comments