fix: incorrect partial url on backwards navigation (#2510)
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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("/");
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user