Skip to content

fix: safe FormData detection for WeChat Mini Program (#7306)#7324

Merged
jasonsaayman merged 2 commits intoaxios:v1.xfrom
Shiwaangee:fix/wechat-formdata
Feb 14, 2026
Merged

fix: safe FormData detection for WeChat Mini Program (#7306)#7324
jasonsaayman merged 2 commits intoaxios:v1.xfrom
Shiwaangee:fix/wechat-formdata

Conversation

@Shiwaangee
Copy link
Contributor

Problem:
Axios throws "TypeError: Cannot read property 'FormData' of undefined" in WeChat Mini Program environments because it directly accesses self/window.FormData. These globals are not available in that environment, causing a crash on import.

Fix:
Introduce safe global detection (globalThis → self → window → global) and guard FormData usage via FormDataCtor. This ensures Axios does not crash when FormData is absent, while preserving existing behavior in browsers and Node.js.

Tests:
All unit and browser tests pass locally. The change is a pure JS guard and does not alter behavior in environments where FormData exists.

Code change:

- typeof FormData === 'function' && thing instanceof FormData
+ FormDataCtor && thing instanceof FormDataCtor
Closes #7306.

@Shiwaangee
Copy link
Contributor Author

Hi maintainers 👋, this PR fixes issue #7306 by safely detecting FormData in WeChat Mini Programs.
All tests pass locally, and the change is scoped to a safe guard without affecting existing environments.
Looking forward to your review!

@jasonsaayman jasonsaayman added priority::medium A medium priority commit::fix The PR is related to a bugfix labels Feb 6, 2026
@jasonsaayman jasonsaayman self-requested a review February 6, 2026 11:06
@jasonsaayman
Copy link
Member

@cubic-dev-ai

@cubic-dev-ai
Copy link
Contributor

cubic-dev-ai bot commented Feb 6, 2026

@cubic-dev-ai

@jasonsaayman I have started the AI code review. It will take a few minutes to complete.

Copy link
Contributor

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

Choose a reason for hiding this comment

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

No issues found across 1 file

Confidence score: 5/5

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

@jasonsaayman jasonsaayman merged commit 672491d into axios:v1.x Feb 14, 2026
6 checks passed
@Shiwaangee
Copy link
Contributor Author

Thank you for reviewing and merging this PR. Happy to see this fix helping Axios users in WeChat Mini Programs.

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.

2 participants