Skip to content

use typeof for cross-realm function detection#2637

Open
erietz wants to merge 3 commits intoopenapi-ts:mainfrom
erietz:fix/instanceof-function-cross-realm
Open

use typeof for cross-realm function detection#2637
erietz wants to merge 3 commits intoopenapi-ts:mainfrom
erietz:fix/instanceof-function-cross-realm

Conversation

@erietz
Copy link

@erietz erietz commented Feb 20, 2026

Replace instanceof Function with typeof === 'function' in defaultBodySerializer to fix form-urlencoded body serialization in environments with separate JavaScript realms (e.g., Jest with experimental VM modules).

The instanceof check fails across realms because the Function constructor differs between realms, causing headers.get to not be recognized as a function even though it is one.

Changes

Related issue here #1762

How to Review

I've created a minimal example in this repo https://github.com/erietz/openapi-fetch-bug

Checklist

  • Unit tests updated
  • docs/ updated (if necessary)
  • pnpm run update:examples run (only applicable for openapi-typescript)

Replace `instanceof Function` with `typeof === 'function'` in
`defaultBodySerializer` to fix form-urlencoded body serialization in
environments with separate JavaScript realms (e.g., Jest with
experimental VM modules).

The instanceof check fails across realms because the Function
constructor differs between realms, causing headers.get to not be
recognized as a function even though it is one.
@erietz erietz requested a review from a team as a code owner February 20, 2026 23:38
@erietz erietz requested a review from duncanbeevers February 20, 2026 23:38
@netlify
Copy link

netlify bot commented Feb 20, 2026

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 89a599e

@changeset-bot
Copy link

changeset-bot bot commented Feb 20, 2026

⚠️ No Changeset found

Latest commit: 1883ea8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@drwpow
Copy link
Contributor

drwpow commented Feb 21, 2026

Thank you! I’m fine with this change, I don’t think there was an intentional reason for instanceof.

If you could submit a changeset (see comment), and fix the lint errors, would be happy to approve & merge 🙂

@erietz
Copy link
Author

erietz commented Feb 23, 2026

Good morning @drwpow, I've got the lint errors fixed up and a changeset created.

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