Skip to content

fix: support node 22 xhr compatibility#245

Merged
fatso83 merged 6 commits intomainfrom
issue-218-node-22
Mar 3, 2026
Merged

fix: support node 22 xhr compatibility#245
fatso83 merged 6 commits intomainfrom
issue-218-node-22

Conversation

@fatso83
Copy link
Copy Markdown
Contributor

@fatso83 fatso83 commented Mar 3, 2026

Attempt at finishing #218

Summary

  • separate fake XHR Blob and FormData handling from bare global assumptions so Node 22+ works when FileReader or FormData are absent in a given context
  • update blob response assertions to use Blob.text() and align support declarations/CI with Node 22+
  • fix stale unsafeHeadersEnabled tests to use nise's fake server/XHR fixtures instead of removed sinon.fakeServer APIs

@socket-security
Copy link
Copy Markdown

socket-security Bot commented Mar 3, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​sinonjs/​fake-timers@​15.1.0 ⏵ 15.1.110010010092 +6100

View full report

@fatso83 fatso83 merged commit 876047d into main Mar 3, 2026
8 checks passed
@fatso83 fatso83 deleted the issue-218-node-22 branch March 3, 2026 05:36
@fatso83
Copy link
Copy Markdown
Contributor Author

fatso83 commented Mar 3, 2026

the change is specifically about not assuming those APIs always exist together.

What the PR actually changes:

  • In lib/fake-xhr/index.js, FormData is now looked up at runtime through the global object before doing instanceof checks. That means:
    • if FormData exists, send(formData) still behaves as FormData;
    • if FormData does not exist in that runtime/context, nise no longer throws a ReferenceError.
  • In lib/fake-xhr/blob.js and lib/fake-xhr/index.js, blob support is based on Blob, not FileReader. That means blob responses still work when
    Blob exists even if FileReader does not.
  • In lib/fake-xhr/index.test.js, blob assertions were changed from FileReader to Blob.text(). That is a test adaptation to modern Node, but it
    matches the production behavior change above rather than papering over it.

What it does not do:

  • It does not polyfill FormData.
  • It does not polyfill FileReader.
  • It does not guarantee support for code paths that truly require FileReader in an environment where FileReader is absent.

In short, the PR preserves FormData behavior when FormData exists, preserves blob behavior when Blob exists, and removes the incorrect dependency on FileReader for blob support. It is not “adding FileReader support”; it is removing the false assumption that FileReader must exist for blob responses to work.

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.

1 participant