[PR #426] [MERGED] fix: next/form submitter overrides and query-string GET URLs #564

Closed
opened 2026-05-06 13:08:47 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/426
Author: @JaredStowell
Created: 3/10/2026
Status: Merged
Merged: 3/11/2026
Merged by: @james-elicx

Base: mainHead: jstowell/fix-next-form-submitter-and-query-handling


📝 Commits (3)

  • a30cc44 Add submitter handling to form shim
  • c48d610 Update form shim URL validation
  • eff8c84 Fix form submit attribute casing

📊 Changes

11 files changed (+677 additions, -51 deletions)

View changed files

📝 packages/vinext/src/shims/form.tsx (+136 -9)
📝 packages/vinext/src/shims/link.tsx (+2 -1)
📝 packages/vinext/src/shims/router.ts (+2 -2)
📝 packages/vinext/src/utils/query.ts (+22 -0)
📝 tests/e2e/app-router/form.spec.ts (+81 -28)
tests/fixtures/app-basic/app/search-alt/page.tsx (+19 -0)
📝 tests/fixtures/app-basic/app/search/page.tsx (+4 -2)
📝 tests/fixtures/app-basic/app/search/search-form.tsx (+53 -6)
📝 tests/form.test.ts (+289 -3)
📝 tests/link.test.ts (+22 -0)
tests/query.test.ts (+47 -0)

📄 Description

Fix next/form GET submissions so they preserve existing query strings and honor the clicked submitter's overrides.

This fixes two concrete bugs:

  • GET forms with an existing query string in action built malformed URLs
  • clicked submitter overrides were ignored, so formAction, formMethod, and submitter name=value were not applied

What changed

  • Updated next/form to:

    • preserve existing query params when building GET navigation URLs
    • read the clicked submitter from the submit event
    • honor submitter formAction
    • honor submitter formMethod
    • include submitter name=value in submitted form data
    • fall back gracefully when FormData(form, submitter) is unavailable
  • Added a shared URL helper for safe query param merging and reused it in:

    • next/form
    • next/link object href resolution
    • router object URL resolution

Tests

Added/updated coverage for:

  • direct next/form submit interception behavior
  • GET actions with existing query strings
  • submitter formAction
  • submitter formMethod="GET" overriding a POST form
  • submitter name=value
  • repeated App Router form navigation behavior
  • object Link hrefs that already contain query strings and hashes

Verification

Ran:

  • pnpm test tests/form.test.ts tests/query.test.ts tests/link.test.ts tests/shims.test.ts -t "next/form|Form|appendSearchParamsToUrl|Link resolveHref"
  • PLAYWRIGHT_PROJECT=app-router pnpm run test:e2e tests/e2e/app-router/form.spec.ts --repeat-each 4
  • pnpm run fmt
  • pnpm run typecheck
  • pnpm run lint
  • pnpm run build
  • pnpm test

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/426 **Author:** [@JaredStowell](https://github.com/JaredStowell) **Created:** 3/10/2026 **Status:** ✅ Merged **Merged:** 3/11/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `jstowell/fix-next-form-submitter-and-query-handling` --- ### 📝 Commits (3) - [`a30cc44`](https://github.com/cloudflare/vinext/commit/a30cc4474b8d63b1e277571d8c7087bbb7774f10) Add submitter handling to form shim - [`c48d610`](https://github.com/cloudflare/vinext/commit/c48d610cb8176014259162d97722111a6371610b) Update form shim URL validation - [`eff8c84`](https://github.com/cloudflare/vinext/commit/eff8c843498417bb0fd48dc3a16d45f52c75fd3f) Fix form submit attribute casing ### 📊 Changes **11 files changed** (+677 additions, -51 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/shims/form.tsx` (+136 -9) 📝 `packages/vinext/src/shims/link.tsx` (+2 -1) 📝 `packages/vinext/src/shims/router.ts` (+2 -2) 📝 `packages/vinext/src/utils/query.ts` (+22 -0) 📝 `tests/e2e/app-router/form.spec.ts` (+81 -28) ➕ `tests/fixtures/app-basic/app/search-alt/page.tsx` (+19 -0) 📝 `tests/fixtures/app-basic/app/search/page.tsx` (+4 -2) 📝 `tests/fixtures/app-basic/app/search/search-form.tsx` (+53 -6) 📝 `tests/form.test.ts` (+289 -3) 📝 `tests/link.test.ts` (+22 -0) ➕ `tests/query.test.ts` (+47 -0) </details> ### 📄 Description Fix `next/form` GET submissions so they preserve existing query strings and honor the clicked submitter's overrides. This fixes two concrete bugs: - GET forms with an existing query string in `action` built malformed URLs - clicked submitter overrides were ignored, so `formAction`, `formMethod`, and submitter `name=value` were not applied ## What changed - Updated `next/form` to: - preserve existing query params when building GET navigation URLs - read the clicked submitter from the submit event - honor submitter `formAction` - honor submitter `formMethod` - include submitter `name=value` in submitted form data - fall back gracefully when `FormData(form, submitter)` is unavailable - Added a shared URL helper for safe query param merging and reused it in: - `next/form` - `next/link` object href resolution - router object URL resolution ## Tests Added/updated coverage for: - direct `next/form` submit interception behavior - GET actions with existing query strings - submitter `formAction` - submitter `formMethod="GET"` overriding a POST form - submitter `name=value` - repeated App Router form navigation behavior - object `Link` hrefs that already contain query strings and hashes ## Verification Ran: - `pnpm test tests/form.test.ts tests/query.test.ts tests/link.test.ts tests/shims.test.ts -t "next/form|Form|appendSearchParamsToUrl|Link resolveHref"` - `PLAYWRIGHT_PROJECT=app-router pnpm run test:e2e tests/e2e/app-router/form.spec.ts --repeat-each 4` - `pnpm run fmt` - `pnpm run typecheck` - `pnpm run lint` - `pnpm run build` - `pnpm test` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:08:47 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#564
No description provided.