fix(partial): form dialog method not supported (#2927)

The `<form>` method value `dialog` does no network request, so we should
ignore it for partials.

Fixes https://github.com/denoland/fresh/issues/2885
This commit is contained in:
Marvin Hagemeister
2025-05-12 21:19:19 +02:00
committed by GitHub
parent 95b82f5281
commit d2da471d67
2 changed files with 40 additions and 4 deletions
+1 -4
View File
@@ -219,10 +219,7 @@ document.addEventListener("submit", async (e) => {
const lowerMethod =
e.submitter?.getAttribute("formmethod")?.toLowerCase() ??
el.method.toLowerCase();
if (
lowerMethod !== "get" && lowerMethod !== "post" &&
lowerMethod !== "dialog"
) {
if (lowerMethod !== "get" && lowerMethod !== "post") {
return;
}
+39
View File
@@ -1833,6 +1833,45 @@ Deno.test({
},
});
Deno.test({
name: "partials - submit form dialog should do nothing",
fn: async () => {
const app = testApp()
.post("/partial", () => {
throw new Error("FAIL");
})
.get("/", (ctx) => {
return ctx.render(
<Doc>
<div f-client-nav>
<dialog open>
<p>Greetings, one and all!</p>
<form method="dialog">
<Partial name="foo">
<p class="init">init</p>
</Partial>
<SelfCounter />
<button type="submit" class="update">OK</button>
</form>
</dialog>
</div>
</Doc>,
);
});
await withBrowserApp(app, async (page, address) => {
await page.goto(address, { waitUntil: "load" });
await page.locator(".ready").wait();
await page.locator(".increment").click();
await waitForText(page, ".output", "1");
await page.locator(".update").click();
await page.locator("dialog:not([open])").wait();
});
},
});
Deno.test({
name: "partials - submit form redirect",
fn: async () => {