Skip to content

fix(form): honor encType when selecting request body - #13997

Merged
bluebill1049 merged 3 commits into
react-hook-form:masterfrom
wozhenbang2004:patch-3
Nov 7, 2026
Merged

bluebill1049 merged 3 commits into
react-hook-form:masterfrom
wozhenbang2004:patch-3

Conversation

@wozhenbang2004

Copy link
Copy Markdown
Contributor

Proposed Changes

When Form receives both encType and a Content-Type header, it can send a body using a different encoding from the final header. For example, encType="application/x-www-form-urlencoded" with a JSON header sends a JSON body under a URL-encoded content type. A differently cased header can also be duplicated when Fetch normalizes the names.

Use the existing non-multipart encType precedence for both body selection and the final header, replacing overridden header names case-insensitively. Preserve multipart boundary handling, other headers, and the caller-provided headers object.

Add 18 regression and compatibility cases for JSON, URL-encoded and text bodies, mixed-case headers, and multipart combinations. Ten new cases fail against the original implementation.

Validation with Node 22:

  • 133 suites, 1,850 unit tests and 26 snapshots passed.
  • All 90 existing Chromium E2E tests passed with one worker and no retries, using a local browser/server configuration. Test files and assertions are unchanged.
  • pnpm type, pnpm test:type, lint, Prettier, builds, and both API Extractor checks passed. No added lint warnings; the API report is unchanged.

Type of change

  • Bug fix

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes

Use the non-multipart encType for body encoding and replace Content-Type headers case-insensitively. Preserve existing multipart boundary handling.
Cover conflicting encodings, mixed-case Content-Type headers, and multipart controls. Check the normalized request headers and body while preserving other headers and the caller-provided object.
@bluebill1049
bluebill1049 merged commit 70dbcda into react-hook-form:master Nov 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants