diff --git a/packages/fresh/src/runtime/client/partials.ts b/packages/fresh/src/runtime/client/partials.ts
index d9da54b4..bd5d3b56 100644
--- a/packages/fresh/src/runtime/client/partials.ts
+++ b/packages/fresh/src/runtime/client/partials.ts
@@ -132,7 +132,7 @@ document.addEventListener("click", async (e) => {
partial ? partial : nextUrl.href,
location.href,
);
- await fetchPartials(nextUrl, partialUrl);
+ await fetchPartials(nextUrl, partialUrl, true);
updateLinks(nextUrl);
scrollTo({ left: 0, top: 0, behavior: "instant" });
} finally {
@@ -155,7 +155,7 @@ document.addEventListener("click", async (e) => {
partial,
location.href,
);
- await fetchPartials(partialUrl, partialUrl);
+ await fetchPartials(partialUrl, partialUrl, false);
}
}
});
@@ -192,7 +192,7 @@ addEventListener("popstate", async (e) => {
const url = new URL(location.href, location.origin);
try {
- await fetchPartials(url, url);
+ await fetchPartials(url, url, true);
updateLinks(url);
scrollTo({
left: state.scrollX ?? 0,
@@ -254,7 +254,7 @@ document.addEventListener("submit", async (e) => {
init = { body: new FormData(el, e.submitter), method: lowerMethod };
}
- await fetchPartials(actionUrl, partialUrl, init);
+ await fetchPartials(actionUrl, partialUrl, true, init);
}
}
});
@@ -282,6 +282,7 @@ function updateLinks(url: URL) {
async function fetchPartials(
actualUrl: URL,
partialUrl: URL,
+ shouldNavigate: boolean,
init: RequestInit = {},
) {
init.redirect = "follow";
@@ -296,7 +297,10 @@ async function fetchPartials(
}
}
- maybeUpdateHistory(actualUrl);
+ if (shouldNavigate) {
+ maybeUpdateHistory(actualUrl);
+ }
+
await applyPartials(res);
}
diff --git a/packages/fresh/tests/partials_test.tsx b/packages/fresh/tests/partials_test.tsx
index 9b8e860a..aae84209 100644
--- a/packages/fresh/tests/partials_test.tsx
+++ b/packages/fresh/tests/partials_test.tsx
@@ -1404,10 +1404,6 @@ Deno.test({
await page.locator(".update").click();
- await page.waitForFunction(() => {
- const url = new URL(window.location.href);
- return url.pathname === "/partial";
- });
await page.locator(".done").wait();
await waitForText(page, ".output", "1");
});
@@ -2665,6 +2661,46 @@ Deno.test({
},
});
+Deno.test({
+ name: "partials - button should not update history",
+ fn: async () => {
+ const app = testApp()
+ .get("/other", (ctx) => {
+ return ctx.render(
+
+
+ other
+
+ ,
+ );
+ })
+ .get("/", (ctx) => {
+ return ctx.render(
+
+
+ ,
+ );
+ });
+
+ await withBrowserApp(app, async (page, address) => {
+ await page.goto(address, { waitUntil: "load" });
+ await page.locator(".ready").wait();
+ await page.locator("button").click();
+ await page.locator(".done").wait();
+
+ const rawUrl = await page.evaluate(() => window.location.href);
+ const url = new URL(rawUrl);
+ expect(`${url.pathname}${url.search}`).toEqual("/");
+ });
+ },
+});
+
Deno.test({
name: "partials - backwards navigation should keep URLs",
fn: async () => {