Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve Frame Visit caching issue #644

Merged
merged 1 commit into from
Jul 28, 2022
Merged
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
4 changes: 2 additions & 2 deletions src/core/frames/frame_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ export class FrameController
viewInvalidated() {}

// Frame renderer delegate
frameExtracted(element: FrameElement) {
this.previousFrameElement = element
willRenderFrame(currentElement: FrameElement, _newElement: FrameElement) {
this.previousFrameElement = currentElement.cloneNode(true)
}

visitCachedSnapshot = ({ element }: Snapshot) => {
Expand Down
4 changes: 2 additions & 2 deletions src/core/frames/frame_renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Render, Renderer } from "../renderer"
import { Snapshot } from "../snapshot"

export interface FrameRendererDelegate {
frameExtracted(element: FrameElement): void
willRenderFrame(currentElement: FrameElement, newElement: FrameElement): void
}

export class FrameRenderer extends Renderer<FrameElement> {
Expand Down Expand Up @@ -52,7 +52,7 @@ export class FrameRenderer extends Renderer<FrameElement> {
}

loadFrameElement() {
this.delegate.frameExtracted(this.newElement.cloneNode(true))
this.delegate.willRenderFrame(this.currentElement, this.newElement)
this.renderElement(this.currentElement, this.newElement)
}

Expand Down
33 changes: 28 additions & 5 deletions src/tests/functional/frame_navigation_tests.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import { test } from "@playwright/test"
import { getFromLocalStorage, nextEventNamed, nextEventOnTarget, pathname } from "../helpers/page"
import { getFromLocalStorage, nextBeat, nextEventNamed, nextEventOnTarget, pathname } from "../helpers/page"
import { assert } from "chai"

test.beforeEach(async ({ page }) => {
await page.goto("/src/tests/fixtures/frame_navigation.html")
})

test("test frame navigation with descendant link", async ({ page }) => {
await page.goto("/src/tests/fixtures/frame_navigation.html")
await page.click("#inside")

await nextEventOnTarget(page, "frame", "turbo:frame-load")
})

test("test frame navigation with self link", async ({ page }) => {
await page.goto("/src/tests/fixtures/frame_navigation.html")
await page.click("#self")

await nextEventOnTarget(page, "frame", "turbo:frame-load")
})

test("test frame navigation with exterior link", async ({ page }) => {
await page.goto("/src/tests/fixtures/frame_navigation.html")
await page.click("#outside")

await nextEventOnTarget(page, "frame", "turbo:frame-load")
Expand All @@ -45,3 +44,27 @@ test("test promoted frame navigation updates the URL before rendering", async ({
assert.equal(await pathname(page.url()), "/src/tests/fixtures/tabs/two.html")
assert.equal(await page.textContent("#tab-content"), "Two")
})

test("test promoted frame navigations are cached", async ({ page }) => {
await page.goto("/src/tests/fixtures/tabs.html")

await page.click("#tab-2")
await nextEventNamed(page, "turbo:frame-render")

assert.equal(await page.textContent("#tab-content"), "Two")

await page.click("#tab-3")
await nextEventNamed(page, "turbo:frame-render")

assert.equal(await page.textContent("#tab-content"), "Three")

await page.goBack()
await nextBeat()

assert.equal(await page.textContent("#tab-content"), "Two")

await page.goBack()
await nextBeat()

assert.equal(await page.textContent("#tab-content"), "One")
})