@@ -197,24 +197,23 @@ export default class IncludeFragmentElement extends HTMLElement {
197197 // We mimic the same event order as <img>, including the spec
198198 // which states events must be dispatched after "queue a task".
199199 // https://www.w3.org/TR/html52/semantics-embedded-content.html#the-img-element
200+ try {
201+ await this . #task( [ 'loadstart' ] )
202+ const response = await this . fetch ( this . request ( ) )
203+ if ( response . status !== 200 ) {
204+ throw new Error ( `Failed to load resource: the server responded with a status of ${ response . status } ` )
205+ }
206+ const ct = response . headers . get ( 'Content-Type' )
207+ if ( ! isWildcard ( this . accept ) && ( ! ct || ! ct . includes ( this . accept ? this . accept : 'text/html' ) ) ) {
208+ throw new Error ( `Failed to load resource: expected ${ this . accept || 'text/html' } but was ${ ct } ` )
209+ }
200210
201- await this . #task( [ 'loadstart' ] )
202- const response = await this . fetch ( this . request ( ) )
203- if ( response . status !== 200 ) {
204- throw new Error ( `Failed to load resource: the server responded with a status of ${ response . status } ` )
205- }
206- const ct = response . headers . get ( 'Content-Type' )
207- if ( ! isWildcard ( this . accept ) && ( ! ct || ! ct . includes ( this . accept ? this . accept : 'text/html' ) ) ) {
208- throw new Error ( `Failed to load resource: expected ${ this . accept || 'text/html' } but was ${ ct } ` )
209- }
210-
211- const responseText : string = await response . text ( )
212- let data : string | CSPTrustedHTMLToStringable = responseText
213- if ( cspTrustedTypesPolicy ) {
214- data = await cspTrustedTypesPolicy . then ( policy => policy . createHTML ( responseText , response ) )
215- }
211+ const responseText : string = await response . text ( )
212+ let data : string | CSPTrustedHTMLToStringable = responseText
213+ if ( cspTrustedTypesPolicy ) {
214+ data = await cspTrustedTypesPolicy . then ( policy => policy . createHTML ( responseText , response ) )
215+ }
216216
217- try {
218217 // Dispatch `load` and `loadend` async to allow
219218 // the `load()` promise to resolve _before_ these
220219 // events are fired.
0 commit comments