fix(partial): buttons outside forms should not trigger navigation (#3584)

`<button>` elements that are not inside a form and have a `f-partial`
attribute should not trigger a history change.
This commit is contained in:
Marvin Hagemeister
2025-10-29 17:49:19 +01:00
committed by GitHub
parent 76dfc65e63
commit 7db37d7ba1
2 changed files with 49 additions and 9 deletions
+40 -4
View File
@@ -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(
<Doc>
<Partial name="foo">
<h1 class="done">other</h1>
</Partial>
</Doc>,
);
})
.get("/", (ctx) => {
return ctx.render(
<Doc>
<div f-client-nav>
<button type="button" f-partial="/other">click</button>
<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("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 () => {