From 6ba11814a5ae696ce756c823d58f9c52b27fbdb6 Mon Sep 17 00:00:00 2001 From: Bobkov Andrey Date: Thu, 20 Jan 2022 13:29:47 +0300 Subject: [PATCH 1/5] fix(visit): will render false for action 'replace' after redirect --- src/core/drive/visit.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/drive/visit.ts b/src/core/drive/visit.ts index 9e900b89b..7d674ce7e 100644 --- a/src/core/drive/visit.ts +++ b/src/core/drive/visit.ts @@ -273,6 +273,7 @@ export class Visit implements FetchRequestDelegate { if (this.redirectedToLocation && !this.followedRedirect && this.response?.redirected) { this.adapter.visitProposedToLocation(this.redirectedToLocation, { action: 'replace', + willRender: false, response: this.response }) this.followedRedirect = true From ba5a8a333d9fe9b07d5a953bef6a01384a9761e2 Mon Sep 17 00:00:00 2001 From: Bobkov Andrey Date: Fri, 21 Jan 2022 01:35:23 +0300 Subject: [PATCH 2/5] feat(eager frame): add test for check fetch eager frame count --- src/tests/fixtures/frames.html | 2 ++ .../fixtures/frames/frame_for_eager.html | 3 +++ src/tests/fixtures/page_with_eager_frame.html | 19 +++++++++++++++++++ src/tests/functional/frame_tests.ts | 18 ++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 src/tests/fixtures/frames/frame_for_eager.html create mode 100644 src/tests/fixtures/page_with_eager_frame.html diff --git a/src/tests/fixtures/frames.html b/src/tests/fixtures/frames.html index 2a84ca2a4..b611136e5 100644 --- a/src/tests/fixtures/frames.html +++ b/src/tests/fixtures/frames.html @@ -121,5 +121,7 @@

Frames: #nested-child


Navigate #frame + + Eager-loaded frame after GET redirect diff --git a/src/tests/fixtures/frames/frame_for_eager.html b/src/tests/fixtures/frames/frame_for_eager.html new file mode 100644 index 000000000..8445b3571 --- /dev/null +++ b/src/tests/fixtures/frames/frame_for_eager.html @@ -0,0 +1,3 @@ + +

Eager-loaded frame: Loaded

+
diff --git a/src/tests/fixtures/page_with_eager_frame.html b/src/tests/fixtures/page_with_eager_frame.html new file mode 100644 index 000000000..9c96fdd7a --- /dev/null +++ b/src/tests/fixtures/page_with_eager_frame.html @@ -0,0 +1,19 @@ + + + + + Frame + + + + +

Eager-loaded frame

+ + +

Eager-loaded frame: NOT Loaded...

+
+ + + Page /src/tests/fixtures/frames.html + + diff --git a/src/tests/functional/frame_tests.ts b/src/tests/functional/frame_tests.ts index b2550e832..ce768a09d 100644 --- a/src/tests/functional/frame_tests.ts +++ b/src/tests/functional/frame_tests.ts @@ -551,6 +551,24 @@ export class FrameTests extends TurboDriveTestCase { this.assert.ok(await this.nextEventOnTarget("frame", "turbo:before-fetch-response")) } + async "test navigating a eager frame with a link[method=get] that does not fetch eager frame twice"() { + await this.clickSelector("#link-to-eager-loaded-frame") + + await this.nextBeat + + const eventLogs = await this.eventLogChannel.read() + const fetchLogs = eventLogs.filter(([name, options]) => + name == "turbo:before-fetch-request" && options?.url?.includes('/src/tests/fixtures/frames/frame_for_eager.html') + ) + this.assert.equal(fetchLogs.length, 1) + + const src = await this.attributeForSelector("#eager-loaded-frame", "src") ?? "" + this.assert.ok(src.includes("/src/tests/fixtures/frames/frame_for_eager.html"), "updates src attribute") + this.assert.equal(await (await this.querySelector("h1")).getVisibleText(), "Eager-loaded frame") + this.assert.equal(await (await this.querySelector("#eager-loaded-frame h2")).getVisibleText(), "Eager-loaded frame: Loaded") + this.assert.equal(await this.pathname, "/src/tests/fixtures/page_with_eager_frame.html") + } + async withoutChangingEventListenersCount(callback: () => void) { const name = "eventListenersAttachedToDocument" const setup = () => { From 03b0f3508f6435f8710ab7871ec6e9e50a754735 Mon Sep 17 00:00:00 2001 From: Andrei Babkou Date: Sun, 1 May 2022 00:29:03 +0300 Subject: [PATCH 3/5] ref(tests): fix eslint errors --- src/tests/functional/frame_tests.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/tests/functional/frame_tests.ts b/src/tests/functional/frame_tests.ts index f59ac731c..186de4da4 100644 --- a/src/tests/functional/frame_tests.ts +++ b/src/tests/functional/frame_tests.ts @@ -585,15 +585,20 @@ export class FrameTests extends TurboDriveTestCase { await this.nextBeat const eventLogs = await this.eventLogChannel.read() - const fetchLogs = eventLogs.filter(([name, options]) => - name == "turbo:before-fetch-request" && options?.url?.includes('/src/tests/fixtures/frames/frame_for_eager.html') + const fetchLogs = eventLogs.filter( + ([name, options]) => + name == "turbo:before-fetch-request" && + options?.url?.includes("/src/tests/fixtures/frames/frame_for_eager.html") ) this.assert.equal(fetchLogs.length, 1) - const src = await this.attributeForSelector("#eager-loaded-frame", "src") ?? "" + const src = (await this.attributeForSelector("#eager-loaded-frame", "src")) ?? "" this.assert.ok(src.includes("/src/tests/fixtures/frames/frame_for_eager.html"), "updates src attribute") this.assert.equal(await (await this.querySelector("h1")).getVisibleText(), "Eager-loaded frame") - this.assert.equal(await (await this.querySelector("#eager-loaded-frame h2")).getVisibleText(), "Eager-loaded frame: Loaded") + this.assert.equal( + await (await this.querySelector("#eager-loaded-frame h2")).getVisibleText(), + "Eager-loaded frame: Loaded" + ) this.assert.equal(await this.pathname, "/src/tests/fixtures/page_with_eager_frame.html") } From a1224e9d5626ca6a839a910f803ed2f8a33e7f5b Mon Sep 17 00:00:00 2001 From: Andrei Babkou Date: Sun, 1 May 2022 00:52:44 +0300 Subject: [PATCH 4/5] ref(test): fix eslint Insert errors --- src/tests/functional/frame_tests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/functional/frame_tests.ts b/src/tests/functional/frame_tests.ts index 186de4da4..9ef2ff199 100644 --- a/src/tests/functional/frame_tests.ts +++ b/src/tests/functional/frame_tests.ts @@ -587,8 +587,8 @@ export class FrameTests extends TurboDriveTestCase { const eventLogs = await this.eventLogChannel.read() const fetchLogs = eventLogs.filter( ([name, options]) => - name == "turbo:before-fetch-request" && - options?.url?.includes("/src/tests/fixtures/frames/frame_for_eager.html") + name == "turbo:before-fetch-request" && + options?.url?.includes("/src/tests/fixtures/frames/frame_for_eager.html") ) this.assert.equal(fetchLogs.length, 1) From 47d4e66de1d84b6066e6b0c84940862a812b4690 Mon Sep 17 00:00:00 2001 From: Andrei Babkou Date: Sun, 1 May 2022 01:23:50 +0300 Subject: [PATCH 5/5] ref(eslint): fix all errors from eslint in branch --- src/core/drive/page_renderer.ts | 4 ++-- src/core/native/browser_adapter.ts | 6 +++--- src/core/session.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/drive/page_renderer.ts b/src/core/drive/page_renderer.ts index 4c0a67e8a..de3e12ba3 100644 --- a/src/core/drive/page_renderer.ts +++ b/src/core/drive/page_renderer.ts @@ -12,13 +12,13 @@ export class PageRenderer extends Renderer { get reloadReason(): ReloadReason { if (!this.newSnapshot.isVisitable) { return { - reason: "turbo_visit_control_is_reload" + reason: "turbo_visit_control_is_reload", } } if (!this.trackedElementsAreIdentical) { return { - reason: "tracked_element_mismatch" + reason: "tracked_element_mismatch", } } } diff --git a/src/core/native/browser_adapter.ts b/src/core/native/browser_adapter.ts index 5073102d4..7fc70317f 100644 --- a/src/core/native/browser_adapter.ts +++ b/src/core/native/browser_adapter.ts @@ -8,7 +8,7 @@ import { uuid, dispatch } from "../../util" export type ReloadReason = StructuredReason | undefined interface StructuredReason { reason: string - context?: {[key: string]: any} + context?: { [key: string]: any } } export class BrowserAdapter implements Adapter { @@ -54,8 +54,8 @@ export class BrowserAdapter implements Adapter { return this.reload({ reason: "request_failed", context: { - statusCode - } + statusCode, + }, }) default: return visit.loadResponse() diff --git a/src/core/session.ts b/src/core/session.ts index 46f2194a0..7ae27bed5 100644 --- a/src/core/session.ts +++ b/src/core/session.ts @@ -128,7 +128,7 @@ export class Session }) } else { this.adapter.pageInvalidated({ - reason: "turbo_disabled" + reason: "turbo_disabled", }) } }