From d2da471d6734371d9bbb7ef735155226325719c8 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Mon, 12 May 2025 21:19:19 +0200 Subject: [PATCH] fix(partial): form `dialog` method not supported (#2927) The `
` method value `dialog` does no network request, so we should ignore it for partials. Fixes https://github.com/denoland/fresh/issues/2885 --- src/runtime/client/partials.ts | 5 +---- tests/partials_test.tsx | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/runtime/client/partials.ts b/src/runtime/client/partials.ts index 41a2c1e9..febffaef 100644 --- a/src/runtime/client/partials.ts +++ b/src/runtime/client/partials.ts @@ -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; } diff --git a/tests/partials_test.tsx b/tests/partials_test.tsx index ae6815af..fe97222b 100644 --- a/tests/partials_test.tsx +++ b/tests/partials_test.tsx @@ -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( + +
+ +

Greetings, one and all!

+ + +

init

+
+ + + +
+
+
, + ); + }); + + 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 () => {