Skip to content

Commit 4da1393

Browse files
committed
Merge branch 'main' into lgarron/csp-trusted-types
2 parents c4e4dac + a887e13 commit 4da1393

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Node CI
22

3-
on: [push]
3+
on: [pull_request, push]
44

55
jobs:
66
build:

src/index.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)