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 navigating to the turbo-root does not use Turbo Drive #1341

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 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
8 changes: 2 additions & 6 deletions src/core/url.js
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ export function getExtension(url) {
}

export function isPrefixedBy(baseURL, url) {
const prefix = getPrefix(url)
const prefix = getPrefix(url) || '/'
leofeyer marked this conversation as resolved.
Show resolved Hide resolved
return baseURL.href === expandURL(prefix).href || baseURL.href.startsWith(prefix)
}

@@ -55,9 +55,5 @@ function getLastPathComponent(url) {
}

function getPrefix(url) {
return addTrailingSlash(url.origin + url.pathname)
}

function addTrailingSlash(value) {
return value.endsWith("/") ? value : value + "/"
url.origin + url.pathname
}
18 changes: 18 additions & 0 deletions src/tests/fixtures/root/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html id="html">
<head>
<meta charset="utf-8">
<title>Turbo</title>
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script>
<script src="/src/tests/fixtures/test.js"></script>
<meta name="turbo-root" content="/src/tests/fixtures/root">
</head>
<body>
<section>
<h1>Root</h1>
<p><a id="link-page-inside" href="/src/tests/fixtures/root/page.html">Link to page inside root</a></p>
<p><a id="link-page-outside" href="/src/tests/fixtures/one.html">Link to page outside root</a></p>
</section>
<div id="messages"></div>
</body>
</html>
17 changes: 17 additions & 0 deletions src/tests/fixtures/root/page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html id="html">
<head>
<meta charset="utf-8">
<title>Turbo</title>
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script>
<script src="/src/tests/fixtures/test.js"></script>
<meta name="turbo-root" content="/src/tests/fixtures/root">
</head>
<body>
<section>
<h1>Root</h1>
<p><a id="link-root" href="/src/tests/fixtures/root">Link to root</a></p>
</section>
<div id="messages"></div>
</body>
</html>
27 changes: 27 additions & 0 deletions src/tests/functional/root_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { test } from "@playwright/test"
import { assert } from "chai"
import { nextBody, pathname, visitAction } from "../helpers/page"

test("test visiting a location inside the root", async ({ page }) => {
leofeyer marked this conversation as resolved.
Show resolved Hide resolved
page.goto("/src/tests/fixtures/root/index.html")
page.click("#link-page-inside")
await nextBody(page)
assert.equal(pathname(page.url()), "/src/tests/fixtures/root/page.html")
assert.notEqual(await visitAction(page), "load")
})

test("test visiting the root itself", async ({ page }) => {
leofeyer marked this conversation as resolved.
Show resolved Hide resolved
page.goto("/src/tests/fixtures/root/page.html")
page.click("#link-root")
await nextBody(page)
assert.equal(pathname(page.url()), "/src/tests/fixtures/root/")
assert.notEqual(await visitAction(page), "load")
})

test("test visiting a location outside the root", async ({ page }) => {
leofeyer marked this conversation as resolved.
Show resolved Hide resolved
page.goto("/src/tests/fixtures/root/index.html")
page.click("#link-page-outside")
await nextBody(page)
assert.equal(pathname(page.url()), "/src/tests/fixtures/one.html")
assert.equal(await visitAction(page), "load")
})