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

Navigate a lazy-loaded turbo-frame #212

Merged
merged 1 commit into from
Apr 7, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/core/frames/frame_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class FrameController implements AppearanceObserverDelegate, FetchRequest
formSubmission?: FormSubmission
private resolveVisitPromise = () => {}
private connected = false
private hasBeenLoaded = false

constructor(element: FrameElement) {
this.element = element
Expand Down Expand Up @@ -53,7 +54,7 @@ export class FrameController implements AppearanceObserverDelegate, FetchRequest
}

sourceURLChanged() {
if (this.loadingStyle == FrameLoadingStyle.eager) {
if (this.loadingStyle == FrameLoadingStyle.eager || this.hasBeenLoaded) {
this.loadSourceURL()
}
}
Expand All @@ -76,6 +77,7 @@ export class FrameController implements AppearanceObserverDelegate, FetchRequest
this.element.loaded = this.visit(this.sourceURL)
this.appearanceObserver.stop()
await this.element.loaded
this.hasBeenLoaded = true
} catch (error) {
this.currentURL = previousURL
throw error
Expand Down
2 changes: 2 additions & 0 deletions src/tests/fixtures/frames/hello.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<h1>Form</h1>
<turbo-frame id="hello">
<h2>Hello from a frame</h2>

<a href="/src/tests/fixtures/frames.html">Navigate #hello</a>
</turbo-frame>
</body>
</html>
14 changes: 14 additions & 0 deletions src/tests/functional/loading_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ export class LoadingTests extends TurboDriveTestCase {
this.assert.equal(await contents.getVisibleText(), "Hello from a frame")
}

async "test navigating a visible frame with loading=lazy navigates"() {
await this.clickSelector("#loading-lazy summary")
await this.nextBeat

const initialContents = await this.querySelector("#hello h2")
this.assert.equal(await initialContents.getVisibleText(), "Hello from a frame")

await this.clickSelector("#hello a")
await this.nextBeat

const navigatedContents = await this.querySelector("#hello h2")
this.assert.equal(await navigatedContents.getVisibleText(), "Frames: #hello")
}

async "test changing src attribute on a frame with loading=lazy defers navigation"() {
const frameContents = "#loading-lazy turbo-frame h2"
await this.nextBeat
Expand Down