fix: incorrect partial url on backwards navigation (#2510)

This commit is contained in:
Marvin Hagemeister
2024-06-08 09:01:12 +02:00
committed by GitHub
parent d6cabce71d
commit 003f2bbb5f
2 changed files with 44 additions and 0 deletions
+1
View File
@@ -288,6 +288,7 @@ async function fetchPartials(
init: RequestInit = {},
) {
init.redirect = "follow";
partialUrl = new URL(partialUrl);
partialUrl.searchParams.set(PARTIAL_SEARCH_PARAM, "true");
const res = await fetch(partialUrl, init);
+43
View File
@@ -2274,3 +2274,46 @@ Deno.test({
});
},
});
Deno.test({
name: "partials - backwards navigation should keep URLs",
fn: async () => {
const app = testApp()
.get("/other", (ctx) => {
return ctx.render(
<Doc>
<Partial name="foo">
<h1 class="done">other</h1>
</Partial>
<SelfCounter />
</Doc>,
);
})
.get("/", (ctx) => {
return ctx.render(
<Doc>
<div f-client-nav>
<a href="/other">other</a>
<Partial name="foo">
<h1 class="init">foo</h1>
</Partial>
<SelfCounter />
</div>
</Doc>,
);
});
await withBrowserApp(app, async (page, address) => {
await page.goto(address, { waitUntil: "load" });
await page.locator(".ready").wait();
await page.locator("a").click();
await page.locator(".done").wait();
await page.evaluate(() => window.history.go(-1));
await page.locator(".init").wait();
const rawUrl = await page.evaluate(() => window.location.href);
const url = new URL(rawUrl);
expect(`${url.pathname}${url.search}`).toEqual("/");
});
},
});