@@ -129,10 +129,10 @@ export default class IncludeFragmentElement extends HTMLElement {
129129 )
130130
131131 async #handleData( ) : Promise < void > {
132- if ( this . #busy) return Promise . resolve ( )
132+ if ( this . #busy) return
133133 this . #busy = true
134+ this . #observer. unobserve ( this )
134135 try {
135- this . #observer. unobserve ( this )
136136 const html = await this . #getData( )
137137
138138 const template = document . createElement ( 'template' )
@@ -142,9 +142,7 @@ export default class IncludeFragmentElement extends HTMLElement {
142142 const canceled = ! this . dispatchEvent (
143143 new CustomEvent ( 'include-fragment-replace' , { cancelable : true , detail : { fragment} } )
144144 )
145- if ( canceled ) {
146- return
147- }
145+ if ( canceled ) return
148146 this . replaceWith ( fragment )
149147 this . dispatchEvent ( new CustomEvent ( 'include-fragment-replaced' ) )
150148 } catch ( _ ) {
@@ -181,28 +179,28 @@ export default class IncludeFragmentElement extends HTMLElement {
181179 // which states events must be dispatched after "queue a task".
182180 // https://www.w3.org/TR/html52/semantics-embedded-content.html#the-img-element
183181
184- try {
185- await this . #task( [ 'loadstart' ] )
186- const response = await this . fetch ( this . request ( ) )
187- if ( response . status !== 200 ) {
188- throw new Error ( `Failed to load resource: the server responded with a status of ${ response . status } ` )
189- }
190- const ct = response . headers . get ( 'Content-Type' )
191- if ( ! isWildcard ( this . accept ) && ( ! ct || ! ct . includes ( this . accept ? this . accept : 'text/html' ) ) ) {
192- throw new Error ( `Failed to load resource: expected ${ this . accept || 'text/html' } but was ${ ct } ` )
193- }
194- const data = await response . text ( )
182+ await this . #task( [ 'loadstart' ] )
183+ const response = await this . fetch ( this . request ( ) )
184+ if ( response . status !== 200 ) {
185+ throw new Error ( `Failed to load resource: the server responded with a status of ${ response . status } ` )
186+ }
187+ const ct = response . headers . get ( 'Content-Type' )
188+ if ( ! isWildcard ( this . accept ) && ( ! ct || ! ct . includes ( this . accept ? this . accept : 'text/html' ) ) ) {
189+ throw new Error ( `Failed to load resource: expected ${ this . accept || 'text/html' } but was ${ ct } ` )
190+ }
191+ const data = await response . text ( )
195192
193+ try {
196194 // Dispatch `load` and `loadend` async to allow
197195 // the `load()` promise to resolve _before_ these
198196 // events are fired.
199- await this . #task( [ 'load' , 'loadend' ] )
197+ this . #task( [ 'load' , 'loadend' ] )
200198 return data
201199 } catch ( error ) {
202200 // Dispatch `error` and `loadend` async to allow
203201 // the `load()` promise to resolve _before_ these
204202 // events are fired.
205- await this . #task( [ 'error' , 'loadend' ] )
203+ this . #task( [ 'error' , 'loadend' ] )
206204 throw error
207205 }
208206 }
0 commit comments