Skip to content

fix: clear RN FormData content type#10898

Merged
jasonsaayman merged 3 commits into
axios:v1.xfrom
cyphercodes:fix-rn-formdata-content-type-10895
May 24, 2026
Merged

fix: clear RN FormData content type#10898
jasonsaayman merged 3 commits into
axios:v1.xfrom
cyphercodes:fix-rn-formdata-content-type-10895

Conversation

@cyphercodes

@cyphercodes cyphercodes commented May 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Clear Content-Type for React Native FormData during adapter config resolution so RN can build multipart requests instead of receiving axios' default application/x-www-form-urlencoded header.

Linked issue

Closes #10895

Changes

  • Treat React Native FormData like browser/web-worker FormData when resolving adapter headers.
  • Add focused regressions for direct resolveConfig behavior and the dispatchRequest default header path.

Checklist

  • Tests added or updated (or N/A with reason)
  • Docs / types updated if public API changed (index.d.ts and index.d.cts) — N/A, no public API change
  • No breaking changes (or called out explicitly above)

Summary by cubic

Clears the default Content-Type for React Native FormData during adapter config resolution so RN can set the multipart boundary correctly. Fixes uploads being sent as application/x-www-form-urlencoded (notably on Android).

Bug Fixes

  • Treat RN FormData like browser/web-worker: unset Content-Type in resolveConfig.

Notes

  • Docs: Add a short note in /docs/ explaining RN FormData now auto-handles Content-Type; release note added in PRE_RELEASE_CHANGELOG.md.
  • Testing: New unit tests in tests/unit/helpers/resolveConfig.test.js and tests/unit/core/dispatchRequest.test.js.
  • Semantic version impact: Patch.

Written for commit ff1f283. Summary will update on new commits. Review in cubic

@cyphercodes cyphercodes requested a review from jasonsaayman as a code owner May 16, 2026 15:29

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@jasonsaayman jasonsaayman added priority::medium A medium priority commit::fix The PR is related to a bugfix labels May 18, 2026
@akshayb03

Copy link
Copy Markdown

@cyphercodes thanks for working on this fix (#10895).

I applied the changes from this PR locally to lib/helpers/resolveConfig.js via patch-package, rebuilt the RN Android app, and retried the same FormData request, but I still see this error on Android:

java.lang.IllegalArgumentException: multipart != application/x-www-form-urlencoded
at okhttp3.MultipartBody$Builder.setType(MultipartBody.kt:241)

Is there any additional build step or generated bundle file that also needs to be updated for the change to take effect, or am I missing something here?

@cyphercodes

Copy link
Copy Markdown
Contributor Author

Thanks for checking this. One likely gotcha: React Native resolves axios through the generated bundle exports (dist/esm/axios.js / dist/browser/axios.cjs), while this PR changes the source file under lib/helpers/resolveConfig.js.

So a patch-package patch that only changes lib/helpers/resolveConfig.js may not affect import axios from 'axios' in a RN app. After running the repo build, the generated RN/browser bundles include the same getParts / RN FormData Content-Type clearing logic.

I re-checked locally on this branch:

  • npx eslint lib/helpers/resolveConfig.js tests/unit/core/dispatchRequest.test.js tests/unit/helpers/resolveConfig.test.js
  • npm run test:vitest:unit -- tests/unit/core/dispatchRequest.test.js tests/unit/helpers/resolveConfig.test.js
  • npm run build and confirmed the generated dist/esm/axios.js / dist/browser/axios.cjs contain the RN FormData branch

For a local patch-package validation, try patching the generated dist entry that your RN bundler is resolving, or build axios from this branch and consume that generated package.

@jasonsaayman jasonsaayman merged commit 7b3369a into axios:v1.x May 24, 2026
26 checks passed
jasonsaayman added a commit that referenced this pull request May 28, 2026
* fix: clear RN FormData content type

* docs: add React Native FormData release note

---------

Co-authored-by: cyphercodes <cyphercodes@users.noreply.github.com>
Co-authored-by: Jason Saayman <jasonsaayman@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit::fix The PR is related to a bugfix priority::medium A medium priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FormData requests crash on RN Android due to incorrect default Content-Type

3 participants