diff --git a/src/core/frames/frame_controller.js b/src/core/frames/frame_controller.js index 07764fc86..25e747f4e 100644 --- a/src/core/frames/frame_controller.js +++ b/src/core/frames/frame_controller.js @@ -270,6 +270,8 @@ export class FrameController { viewRenderedSnapshot(_snapshot, _isPreview, _renderMethod) {} + setLastRenderedLocation() {} + preloadOnLoadLinksForView(element) { session.preloadOnLoadLinksForView(element) } diff --git a/src/core/session.js b/src/core/session.js index 1047d4463..4bdff2e46 100644 --- a/src/core/session.js +++ b/src/core/session.js @@ -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) } diff --git a/src/core/view.js b/src/core/view.js index 7b562563d..5f09e9f28 100644 --- a/src/core/view.js +++ b/src/core/view.js @@ -84,6 +84,8 @@ export class View { } } else if (shouldInvalidate) { this.invalidate(renderer.reloadReason) + } else { + this.delegate.setLastRenderedLocation() } } diff --git a/src/tests/functional/frame_navigation_tests.js b/src/tests/functional/frame_navigation_tests.js index 9927aec87..f0c3b3901 100644 --- a/src/tests/functional/frame_navigation_tests.js +++ b/src/tests/functional/frame_navigation_tests.js @@ -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 }) => {