diff --git a/src/core/frames/frame_controller.ts b/src/core/frames/frame_controller.ts index e7eec013d..4040191a4 100644 --- a/src/core/frames/frame_controller.ts +++ b/src/core/frames/frame_controller.ts @@ -82,7 +82,7 @@ export class FrameController if (this.isIgnoringChangesTo("src")) return if (this.element.isConnected) { - this.loaded = false + this.complete = false } if (this.loadingStyle == FrameLoadingStyle.eager || this.hasBeenLoaded) { @@ -90,8 +90,8 @@ export class FrameController } } - loadedChanged() { - if (this.isIgnoringChangesTo("loaded")) return + completeChanged() { + if (this.isIgnoringChangesTo("complete")) return this.loadSourceURL() } @@ -106,7 +106,7 @@ export class FrameController } private async loadSourceURL() { - if (this.enabled && this.isActive && !this.loaded && this.sourceURL) { + if (this.enabled && this.isActive && !this.complete && this.sourceURL) { this.element.loaded = this.visit(expandURL(this.sourceURL)) this.appearanceObserver.stop() await this.element.loaded @@ -127,7 +127,7 @@ export class FrameController const renderer = new FrameRenderer(this.view.snapshot, snapshot, false, false) if (this.view.renderPromise) await this.view.renderPromise await this.view.render(renderer) - this.loaded = true + this.complete = true session.frameRendered(fetchResponse, this.element) session.frameLoaded(this.element) this.fetchResponseLoaded(fetchResponse) @@ -315,7 +315,7 @@ export class FrameController element = activateElement(container.querySelector(`turbo-frame[src][recurse~=${id}]`), this.sourceURL) if (element) { - await element.loaded + await element.complete return await this.extractForeignFrameElement(element) } @@ -392,16 +392,16 @@ export class FrameController return this.formSubmission !== undefined || this.resolveVisitPromise() !== undefined } - get loaded() { - return this.element.hasAttribute("loaded") + get complete() { + return this.element.hasAttribute("complete") } - set loaded(value: boolean) { - this.ignoringChangesToAttribute("loaded", () => { + set complete(value: boolean) { + this.ignoringChangesToAttribute("complete", () => { if (value) { - this.element.setAttribute("loaded", "") + this.element.setAttribute("complete", "") } else { - this.element.removeAttribute("loaded") + this.element.removeAttribute("complete") } }) } diff --git a/src/elements/frame_element.ts b/src/elements/frame_element.ts index 83c9a8ce1..3f40937d7 100644 --- a/src/elements/frame_element.ts +++ b/src/elements/frame_element.ts @@ -5,12 +5,12 @@ export enum FrameLoadingStyle { lazy = "lazy", } -export type FrameElementObservedAttribute = keyof FrameElement & ("disabled" | "loaded" | "loading" | "src") +export type FrameElementObservedAttribute = keyof FrameElement & ("disabled" | "complete" | "loading" | "src") export interface FrameElementDelegate { connect(): void disconnect(): void - loadedChanged(): void + completeChanged(): void loadingStyleChanged(): void sourceURLChanged(): void disabledChanged(): void @@ -44,7 +44,7 @@ export class FrameElement extends HTMLElement { readonly delegate: FrameElementDelegate static get observedAttributes(): FrameElementObservedAttribute[] { - return ["disabled", "loaded", "loading", "src"] + return ["disabled", "complete", "loading", "src"] } constructor() { @@ -62,7 +62,7 @@ export class FrameElement extends HTMLElement { reload() { const { src } = this - this.removeAttribute("loaded") + this.removeAttribute("complete") this.src = null this.src = src } @@ -70,8 +70,8 @@ export class FrameElement extends HTMLElement { attributeChangedCallback(name: string) { if (name == "loading") { this.delegate.loadingStyleChanged() - } else if (name == "loaded") { - this.delegate.loadedChanged() + } else if (name == "complete") { + this.delegate.completeChanged() } else if (name == "src") { this.delegate.sourceURLChanged() } else { diff --git a/src/tests/functional/frame_tests.ts b/src/tests/functional/frame_tests.ts index cf15f9508..a9afd1316 100644 --- a/src/tests/functional/frame_tests.ts +++ b/src/tests/functional/frame_tests.ts @@ -450,7 +450,7 @@ export class FrameTests extends TurboDriveTestCase { this.assert.equal(await title.getVisibleText(), "Frames") this.assert.equal(await frameTitle.getVisibleText(), "Frame: Loaded") this.assert.equal(await this.pathname, "/src/tests/fixtures/frames/frame.html") - this.assert.ok(await this.hasSelector("#frame[loaded]"), "marks the frame as [loaded]") + this.assert.ok(await this.hasSelector("#frame[complete]"), "marks the frame as [complete]") } async "test navigating frame with a[data-turbo-action=advance] pushes URL state"() { @@ -465,7 +465,7 @@ export class FrameTests extends TurboDriveTestCase { this.assert.equal(await title.getVisibleText(), "Frames") this.assert.equal(await frameTitle.getVisibleText(), "Frame: Loaded") this.assert.equal(await this.pathname, "/src/tests/fixtures/frames/frame.html") - this.assert.ok(await this.hasSelector("#frame[loaded]"), "marks the frame as [loaded]") + this.assert.ok(await this.hasSelector("#frame[complete]"), "marks the frame as [complete]") } async "test navigating frame with form[method=get][data-turbo-action=advance] pushes URL state"() { @@ -480,7 +480,7 @@ export class FrameTests extends TurboDriveTestCase { this.assert.equal(await title.getVisibleText(), "Frames") this.assert.equal(await frameTitle.getVisibleText(), "Frame: Loaded") this.assert.equal(await this.pathname, "/src/tests/fixtures/frames/frame.html") - this.assert.ok(await this.hasSelector("#frame[loaded]"), "marks the frame as [loaded]") + this.assert.ok(await this.hasSelector("#frame[complete]"), "marks the frame as [complete]") } async "test navigating frame with form[method=get][data-turbo-action=advance] to the same URL clears the [aria-busy] and [data-turbo-preview] state"() { @@ -508,7 +508,7 @@ export class FrameTests extends TurboDriveTestCase { this.assert.equal(await title.getVisibleText(), "Frames") this.assert.equal(await frameTitle.getVisibleText(), "Frame: Loaded") this.assert.equal(await this.pathname, "/src/tests/fixtures/frames/frame.html") - this.assert.ok(await this.hasSelector("#frame[loaded]"), "marks the frame as [loaded]") + this.assert.ok(await this.hasSelector("#frame[complete]"), "marks the frame as [complete]") } async "test navigating frame with form[method=post][data-turbo-action=advance] to the same URL clears the [aria-busy] and [data-turbo-preview] state"() { @@ -522,7 +522,7 @@ export class FrameTests extends TurboDriveTestCase { this.assert.equal(await this.attributeForSelector("#frame", "aria-busy"), null, "clears turbo-frame[aria-busy]") this.assert.equal(await this.attributeForSelector("#html", "aria-busy"), null, "clears html[aria-busy]") this.assert.equal(await this.attributeForSelector("#html", "data-turbo-preview"), null, "clears html[aria-busy]") - this.assert.ok(await this.hasSelector("#frame[loaded]"), "marks the frame as [loaded]") + this.assert.ok(await this.hasSelector("#frame[complete]"), "marks the frame as [complete]") } async "test navigating frame with button[data-turbo-action=advance] pushes URL state"() { @@ -537,7 +537,7 @@ export class FrameTests extends TurboDriveTestCase { this.assert.equal(await title.getVisibleText(), "Frames") this.assert.equal(await frameTitle.getVisibleText(), "Frame: Loaded") this.assert.equal(await this.pathname, "/src/tests/fixtures/frames/frame.html") - this.assert.ok(await this.hasSelector("#frame[loaded]"), "marks the frame as [loaded]") + this.assert.ok(await this.hasSelector("#frame[complete]"), "marks the frame as [complete]") } async "test navigating back after pushing URL state from a turbo-frame[data-turbo-action=advance] restores the frames previous contents"() { @@ -573,7 +573,7 @@ export class FrameTests extends TurboDriveTestCase { this.assert.equal(await title.getVisibleText(), "Frames") this.assert.equal(await frameTitle.getVisibleText(), "Frame: Loaded") this.assert.equal(await this.pathname, "/src/tests/fixtures/frames/frame.html") - this.assert.ok(await this.hasSelector("#frame[loaded]"), "marks the frame as [loaded]") + this.assert.ok(await this.hasSelector("#frame[complete]"), "marks the frame as [complete]") } async "test turbo:before-fetch-request fires on the frame element"() { diff --git a/src/tests/functional/loading_tests.ts b/src/tests/functional/loading_tests.ts index 3a433c8df..eb0c74ffc 100644 --- a/src/tests/functional/loading_tests.ts +++ b/src/tests/functional/loading_tests.ts @@ -14,7 +14,7 @@ export class LoadingTests extends TurboDriveTestCase { async "test eager loading within a details element"() { await this.nextBeat this.assert.ok(await this.hasSelector("#loading-eager turbo-frame#frame h2")) - this.assert.ok(await this.hasSelector("#loading-eager turbo-frame[loaded]"), "has [loaded] attribute") + this.assert.ok(await this.hasSelector("#loading-eager turbo-frame[complete]"), "has [complete] attribute") } async "test lazy loading within a details element"() { @@ -22,14 +22,14 @@ export class LoadingTests extends TurboDriveTestCase { const frameContents = "#loading-lazy turbo-frame h2" this.assert.notOk(await this.hasSelector(frameContents)) - this.assert.ok(await this.hasSelector("#loading-lazy turbo-frame:not([loaded])")) + this.assert.ok(await this.hasSelector("#loading-lazy turbo-frame:not([complete])")) await this.clickSelector("#loading-lazy summary") await this.nextBeat const contents = await this.querySelector(frameContents) this.assert.equal(await contents.getVisibleText(), "Hello from a frame") - this.assert.ok(await this.hasSelector("#loading-lazy turbo-frame[loaded]"), "has [loaded] attribute") + this.assert.ok(await this.hasSelector("#loading-lazy turbo-frame[complete]"), "has [complete] attribute") } async "test changing loading attribute from lazy to eager loads frame"() { @@ -101,11 +101,11 @@ export class LoadingTests extends TurboDriveTestCase { const frameContent = "#loading-eager turbo-frame#frame h2" this.assert.ok(await this.hasSelector(frameContent)) - this.assert.ok(await this.hasSelector("#loading-eager turbo-frame[loaded]"), "has [loaded] attribute") + this.assert.ok(await this.hasSelector("#loading-eager turbo-frame[complete]"), "has [complete] attribute") await this.remote.execute(() => (document.querySelector("#loading-eager turbo-frame") as any)?.reload()) this.assert.ok(await this.hasSelector(frameContent)) - this.assert.ok(await this.hasSelector("#loading-eager turbo-frame:not([loaded])"), "clears [loaded] attribute") + this.assert.ok(await this.hasSelector("#loading-eager turbo-frame:not([complete])"), "clears [complete] attribute") } async "test navigating away from a page does not reload its frames"() { @@ -117,23 +117,23 @@ export class LoadingTests extends TurboDriveTestCase { this.assert.equal(requestLogs.length, 1) } - async "test removing the [loaded] attribute of an eager frame reloads the content"() { + async "test removing the [complete] attribute of an eager frame reloads the content"() { await this.nextEventOnTarget("frame", "turbo:frame-load") - await this.remote.execute(() => document.querySelector("#loading-eager turbo-frame")?.removeAttribute("loaded")) + await this.remote.execute(() => document.querySelector("#loading-eager turbo-frame")?.removeAttribute("complete")) await this.nextEventOnTarget("frame", "turbo:frame-load") this.assert.ok( - await this.hasSelector("#loading-eager turbo-frame[loaded]"), - "sets the [loaded] attribute after re-loading" + await this.hasSelector("#loading-eager turbo-frame[complete]"), + "sets the [complete] attribute after re-loading" ) } - async "test changing [src] attribute on a [loaded] frame with loading=lazy defers navigation"() { + async "test changing [src] attribute on a [complete] frame with loading=lazy defers navigation"() { await this.nextEventOnTarget("frame", "turbo:frame-load") await this.clickSelector("#loading-lazy summary") await this.nextEventOnTarget("hello", "turbo:frame-load") - this.assert.ok(await this.hasSelector("#loading-lazy turbo-frame[loaded]"), "lazy frame is loaded") + this.assert.ok(await this.hasSelector("#loading-lazy turbo-frame[complete]"), "lazy frame is complete") this.assert.equal(await (await this.querySelector("#hello h2")).getVisibleText(), "Hello from a frame") await this.clickSelector("#loading-lazy summary") @@ -145,13 +145,13 @@ export class LoadingTests extends TurboDriveTestCase { let src = new URL((await this.attributeForSelector("#hello", "src")) || "") - this.assert.ok(await this.hasSelector("#loading-lazy turbo-frame[loaded]"), "lazy frame is loaded") + this.assert.ok(await this.hasSelector("#loading-lazy turbo-frame[complete]"), "lazy frame is complete") this.assert.equal(src.pathname, "/src/tests/fixtures/frames/hello.html", "lazy frame retains [src]") await this.clickSelector("#link-lazy-frame") await this.noNextEventNamed("turbo:frame-load") - this.assert.ok(await this.hasSelector("#loading-lazy turbo-frame:not([loaded])"), "lazy frame is not loaded") + this.assert.ok(await this.hasSelector("#loading-lazy turbo-frame:not([complete])"), "lazy frame is not complete") await this.clickSelector("#loading-lazy summary") await this.nextEventOnTarget("hello", "turbo:frame-load") @@ -162,7 +162,7 @@ export class LoadingTests extends TurboDriveTestCase { await (await this.querySelector("#loading-lazy turbo-frame h2")).getVisibleText(), "Frames: #hello" ) - this.assert.ok(await this.hasSelector("#loading-lazy turbo-frame[loaded]"), "lazy frame is loaded") + this.assert.ok(await this.hasSelector("#loading-lazy turbo-frame[complete]"), "lazy frame is complete") this.assert.equal(src.pathname, "/src/tests/fixtures/frames.html", "lazy frame navigates") }