Skip to content

Commit d2da471

Browse files
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 #2885
1 parent 95b82f5 commit d2da471

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

src/runtime/client/partials.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,7 @@ document.addEventListener("submit", async (e) => {
219219
const lowerMethod =
220220
e.submitter?.getAttribute("formmethod")?.toLowerCase() ??
221221
el.method.toLowerCase();
222-
if (
223-
lowerMethod !== "get" && lowerMethod !== "post" &&
224-
lowerMethod !== "dialog"
225-
) {
222+
if (lowerMethod !== "get" && lowerMethod !== "post") {
226223
return;
227224
}
228225

tests/partials_test.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,45 @@ Deno.test({
18331833
},
18341834
});
18351835

1836+
Deno.test({
1837+
name: "partials - submit form dialog should do nothing",
1838+
fn: async () => {
1839+
const app = testApp()
1840+
.post("/partial", () => {
1841+
throw new Error("FAIL");
1842+
})
1843+
.get("/", (ctx) => {
1844+
return ctx.render(
1845+
<Doc>
1846+
<div f-client-nav>
1847+
<dialog open>
1848+
<p>Greetings, one and all!</p>
1849+
<form method="dialog">
1850+
<Partial name="foo">
1851+
<p class="init">init</p>
1852+
</Partial>
1853+
<SelfCounter />
1854+
<button type="submit" class="update">OK</button>
1855+
</form>
1856+
</dialog>
1857+
</div>
1858+
</Doc>,
1859+
);
1860+
});
1861+
1862+
await withBrowserApp(app, async (page, address) => {
1863+
await page.goto(address, { waitUntil: "load" });
1864+
await page.locator(".ready").wait();
1865+
1866+
await page.locator(".increment").click();
1867+
await waitForText(page, ".output", "1");
1868+
1869+
await page.locator(".update").click();
1870+
await page.locator("dialog:not([open])").wait();
1871+
});
1872+
},
1873+
});
1874+
18361875
Deno.test({
18371876
name: "partials - submit form redirect",
18381877
fn: async () => {

0 commit comments

Comments
 (0)