From dd2d2b58db356e671b0ebe38145151e19193d830 Mon Sep 17 00:00:00 2001 From: Leo Feyer <1192057+leofeyer@users.noreply.github.com> Date: Thu, 21 Nov 2024 12:06:57 +0100 Subject: [PATCH 1/2] Fix navigating to the turbo-root does not use Turbo Drive --- src/core/url.js | 6 +----- src/tests/fixtures/root/index.html | 18 ++++++++++++++++++ src/tests/fixtures/root/page.html | 17 +++++++++++++++++ src/tests/functional/root_test.js | 27 +++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 src/tests/fixtures/root/index.html create mode 100644 src/tests/fixtures/root/page.html create mode 100644 src/tests/functional/root_test.js diff --git a/src/core/url.js b/src/core/url.js index ec7955fad..3c5608c74 100644 --- a/src/core/url.js +++ b/src/core/url.js @@ -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 } diff --git a/src/tests/fixtures/root/index.html b/src/tests/fixtures/root/index.html new file mode 100644 index 000000000..3563f3f65 --- /dev/null +++ b/src/tests/fixtures/root/index.html @@ -0,0 +1,18 @@ + + + + + Turbo + + + + + +
+

Root

+

Link to page inside root

+

Link to page outside root

+
+
+ + diff --git a/src/tests/fixtures/root/page.html b/src/tests/fixtures/root/page.html new file mode 100644 index 000000000..9fa53bf71 --- /dev/null +++ b/src/tests/fixtures/root/page.html @@ -0,0 +1,17 @@ + + + + + Turbo + + + + + +
+

Root

+

Link to root

+
+
+ + diff --git a/src/tests/functional/root_test.js b/src/tests/functional/root_test.js new file mode 100644 index 000000000..88c320e71 --- /dev/null +++ b/src/tests/functional/root_test.js @@ -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 }) => { + 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 }) => { + 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 }) => { + 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") +}) From 784576e06053b835a1bc46ad5a0f27db9e073d76 Mon Sep 17 00:00:00 2001 From: Leo Feyer <1192057+leofeyer@users.noreply.github.com> Date: Mon, 25 Nov 2024 09:10:46 +0100 Subject: [PATCH 2/2] Fix a 'Cannot read properties of undefined' error --- src/core/url.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/url.js b/src/core/url.js index 3c5608c74..a528f39f3 100644 --- a/src/core/url.js +++ b/src/core/url.js @@ -25,7 +25,7 @@ export function getExtension(url) { } export function isPrefixedBy(baseURL, url) { - const prefix = getPrefix(url) + const prefix = getPrefix(url) || '/' return baseURL.href === expandURL(prefix).href || baseURL.href.startsWith(prefix) }