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

[fix] loading after completed lazy loading and restored visit #1227

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
6 changes: 5 additions & 1 deletion src/core/frames/frame_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ export class FrameController {
if (!this.#connected) {
this.#connected = true
if (this.loadingStyle == FrameLoadingStyle.lazy) {
this.appearanceObserver.start()
if (this.complete) {
this.#hasBeenLoaded = true
} else {
this.appearanceObserver.start()
}
} else {
this.#loadSourceURL()
}
Expand Down
3 changes: 3 additions & 0 deletions src/tests/fixtures/frames/hello.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ <h2>Hello from a frame</h2>
<form id="permanent-form-in-frame" data-turbo-permanent>
<input id="permanent-descendant-input-in-frame" type="text" name="query" placeholder="Permanent descendant input in frame">
</form>

<a id="two" href="/src/tests/fixtures/two.html" data-turbo-frame="_top">Two</a>
<a id="hello2" href="/src/tests/fixtures/frames/hello_2.html">To hello 2</a>
</turbo-frame>
</body>
</html>
15 changes: 15 additions & 0 deletions src/tests/fixtures/frames/hello_2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Frames: Hello 2</title>
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script>
<script src="/src/tests/fixtures/test.js"></script>
</head>
<body>
<h1>Hello 2</h1>
<turbo-frame id="hello">
<h2>Hello 2 from a frame</h2>
</turbo-frame>
</body>
</html>
18 changes: 18 additions & 0 deletions src/tests/functional/loading_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ test("lazy loading within a details element", async ({ page }) => {
assert.ok(await hasSelector(page, "#loading-lazy turbo-frame[complete]"), "has [complete] attribute")
})

test("loading after completed lazy loading and restored visit", async ({ page }) => {
const frameContents = "#loading-lazy turbo-frame h2"
await page.click("#loading-lazy summary")
await nextBeat()

const contents = await page.locator(frameContents)
assert.equal(await contents.textContent(), "Hello from a frame")
await page.click("#two")
await nextBeat()

await page.goBack()
await page.click("#hello2")
await nextBeat()

const contents2 = await page.locator(frameContents)
assert.equal(await contents2.textContent(), "Hello 2 from a frame")
})

test("changing loading attribute from lazy to eager loads frame", async ({ page }) => {
const frameContents = "#loading-lazy turbo-frame h2"
await nextBeat()
Expand Down