Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/elements/frame_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,24 @@ export class FrameElement extends HTMLElement {
}

connectedCallback() {
this.delegate.connect()
if (this.delegate) {
this.delegate.connect()
}
}

disconnectedCallback() {
this.delegate.disconnect()
if (this.delegate) {
this.delegate.disconnect()
}
}

reload() {
return this.delegate.sourceURLReloaded()
return this.delegate?.sourceURLReloaded()
}

attributeChangedCallback(name) {
if (!this.delegate) return

if (name == "loading") {
this.delegate.loadingStyleChanged()
} else if (name == "src") {
Expand Down Expand Up @@ -161,7 +167,7 @@ export class FrameElement extends HTMLElement {
* Determines if the element has finished loading
*/
get complete() {
return !this.delegate.isLoading
return this.delegate ? !this.delegate.isLoading : true
}

/**
Expand Down
18 changes: 18 additions & 0 deletions src/tests/functional/frame_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1090,3 +1090,21 @@ async function withoutChangingEventListenersCount(page, callback) {
function frameScriptEvaluationCount(page) {
return page.evaluate(() => window.frameScriptEvaluationCount)
}

test("FrameElement does not throw when delegate is undefined in connectedCallback (fixes #1364)", async ({ page }) => {
const errorThrown = await page.evaluate(() => {
const frame = document.createElement("turbo-frame")
frame.id = "test-frame-1364"
frame.delegate = undefined

try {
document.body.appendChild(frame)
document.body.removeChild(frame)
return false
} catch (e) {
return true
}
})

expect(errorThrown, "FrameElement should not throw when delegate is undefined").toBe(false)
})