File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ export default class IncludeFragmentElement extends HTMLElement {
111111 attributeChangedCallback ( attribute : string , oldVal :string | null ) : void {
112112 if ( attribute === 'src' ) {
113113 // Source changed after attached so replace element.
114- if ( this . isConnected ) {
114+ if ( this . isConnected && this . loading === 'eager' ) {
115115 handleData ( this )
116116 }
117117 } else if ( attribute === 'loading' ) {
Original file line number Diff line number Diff line change @@ -466,6 +466,21 @@ suite('include-fragment-element', function() {
466466 ] )
467467 } )
468468
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+
469484 test ( 'loading=lazy loads as soon as element visible on page' , function ( ) {
470485 const div = document . createElement ( 'div' )
471486 div . innerHTML = '<include-fragment loading="lazy" src="/hello">loading</include-fragment>'
You can’t perform that action at this time.
0 commit comments