Skip to content

Commit

Permalink
Merge pull request #1079 from brunoprietog/use-pathname-for-refreshes
Browse files Browse the repository at this point in the history
Page refreshes: Use pathname instead of href to detect if locations are equal
  • Loading branch information
jorgemanrubia committed Dec 7, 2023
2 parents b493fca + e7a2c7a commit 06ee1fe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/drive/page_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class PageView extends View {
}

isPageRefresh(visit) {
return !visit || (this.lastRenderedLocation.href === visit.location.href && visit.action === "replace")
return !visit || (this.lastRenderedLocation.pathname === visit.location.pathname && visit.action === "replace")
}

shouldPreserveScrollPosition(visit) {
Expand Down
1 change: 1 addition & 0 deletions src/tests/fixtures/page_refresh.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ <h2>Frame to be preserved</h2>
<h3>Element with Stimulus controller</h3>
</div>

<p><a id="replace-link" data-turbo-action="replace" href="/src/tests/fixtures/page_refresh.html?param=something">Link with params to refresh the page</a></p>
<p><a id="link" href="/src/tests/fixtures/one.html">Link to another page</a></p>

<form id="form" action="/__turbo/refresh" method="post" class="redirect">
Expand Down
7 changes: 7 additions & 0 deletions src/tests/functional/page_refresh_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ test("renders a page refresh with morphing", async ({ page }) => {
await nextEventNamed(page, "turbo:render", { renderMethod: "morph" })
})

test("renders a page refresh with morphing when the paths are the same but search params are diferent", async ({ page }) => {
await page.goto("/src/tests/fixtures/page_refresh.html")

await page.click("#replace-link")
await nextEventNamed(page, "turbo:render", { renderMethod: "morph" })
})

test("doesn't morph when the turbo-refresh-method meta tag is not 'morph'", async ({ page }) => {
await page.goto("/src/tests/fixtures/page_refresh_replace.html")

Expand Down

0 comments on commit 06ee1fe

Please sign in to comment.