use typeof for cross-realm function detection#2637
use typeof for cross-realm function detection#2637erietz wants to merge 3 commits intoopenapi-ts:mainfrom
Conversation
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.
👷 Deploy request for openapi-ts pending review.Visit the deploys page to approve it
|
|
|
Thank you! I’m fine with this change, I don’t think there was an intentional reason for If you could submit a changeset (see comment), and fix the lint errors, would be happy to approve & merge 🙂 |
|
Good morning @drwpow, I've got the lint errors fixed up and a changeset created. |
Replace
instanceof Functionwithtypeof === 'function'indefaultBodySerializerto 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
docs/updated (if necessary)pnpm run update:examplesrun (only applicable for openapi-typescript)