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

Support back button (restore) even if page loaded in frame does not contain matching HEAD #1281

Open
wants to merge 5 commits 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
2 changes: 2 additions & 0 deletions src/core/frames/frame_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ export class FrameController {

viewRenderedSnapshot(_snapshot, _isPreview, _renderMethod) {}

setLastRenderedLocation() {}

preloadOnLoadLinksForView(element) {
session.preloadOnLoadLinksForView(element)
}
Expand Down
6 changes: 5 additions & 1 deletion src/core/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,14 @@ export class Session {
}

viewRenderedSnapshot(_snapshot, _isPreview, renderMethod) {
this.view.lastRenderedLocation = this.history.location
this.setLastRenderedLocation()
this.notifyApplicationAfterRender(renderMethod)
}

setLastRenderedLocation() {
this.view.lastRenderedLocation = this.history.location
}

preloadOnLoadLinksForView(element) {
this.preloader.preloadOnLoadLinksForView(element)
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ export class View {
}
} else if (shouldInvalidate) {
this.invalidate(renderer.reloadReason)
} else {
this.delegate.setLastRenderedLocation()
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/tests/functional/frame_navigation_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,19 @@ test("frame navigation with data-turbo-action", async ({ page }) => {
await nextBeat()

await nextEventOnTarget(page, "empty-head", "turbo:frame-load")
assert.equal(pathname(page.url()), "/src/tests/fixtures/frames/empty_head.html")

const frameText = await page.textContent("#empty-head h2")
let frameText = await page.textContent("#empty-head h2")
assert.equal(frameText, "Frame updated")

const titleText = await page.textContent("h1")
assert.equal(titleText, "Frame navigation tests")

await page.goBack()
await nextEventNamed(page, "turbo:load")
assert.equal(pathname(page.url()), "/src/tests/fixtures/frame_navigation.html")
frameText = await page.textContent("#empty-head #link-to-frame-with-empty-head")
assert.equal(frameText, 'About (a link with data-turbo-action="advance")')
})

test("frame navigation emits fetch-request-error event when offline", async ({ page }) => {
Expand Down