Skip to content

chore(deps): replace isomorphic-fetch with native fetch - #1208

Merged
connorjclark merged 2 commits into
mainfrom
remove-isomorphic-fetch
Nov 12, 2026
Merged

connorjclark merged 2 commits into
mainfrom
remove-isomorphic-fetch

Conversation

@connorjclark

@connorjclark connorjclark commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Removes isomorphic-fetch from @lhci/utils and @lhci/cli, @types/isomorphic-fetch from the root devDependencies, and the old Parcel-era "alias": {"isomorphic-fetch": "clsx"} hack from @lhci/server and @lhci/viewer, in favor of the global fetch built into Node (engines.node is >=22.19.0) and browsers.

@lhci/utils & @lhci/server

  • api-client.js / psi-client.js default to the global fetch (via a small wrapper so it's always invoked unbound and resolved at call time, as browsers and jsdom tests require), and use the global btoa and URL directly. The fetch option types are now typeof fetch.
  • use-api-data.jsx drops the now-redundant URL: window.URL and fetch: window.fetch.bind(window) options when constructing ApiClient.
  • The server/viewer esbuild bundles no longer include the whatwg-fetch polyfill (verified isomorphic-fetch/whatwg-fetch no longer appear in dist/).

@lhci/cli src/fetch.js (proxy support)

The global fetch ignores options.agent, and NODE_USE_ENV_PROXY needs Node 22.21+ (above our >=22.19.0 minimum), so proxy-agent is kept:

  • When ProxyAgent#getProxyForUrl resolves a proxy for the target URL (supporting upper/lowercase http_proxy/https_proxy/all_proxy while keeping NO_PROXY matches on native fetch) or an explicit options.agent is passed, the request goes through a small node:http/node:https implementation using a shared ProxyAgent (or the provided agent) and returns a real Response. It normalizes method/headers/body via new Request(...), sets default user-agent/accept/accept-encoding headers, follows redirects like fetch (follow/manual/error, max 20, 303 / POST-on-301/302 become GET, credentials and host dropped cross-origin), decompresses gzip/deflate (including raw deflate)/br, and sets response.url and response.redirected.
  • Otherwise it calls the global fetch directly.
  • New packages/cli/test/fetch.test.js covers the global-fetch path (including NO_PROXY), the agent path (status/headers/body, default headers, redirects + cross-origin header stripping, compression including raw deflate and empty encoded bodies, 204, errors), and end-to-end http_proxy / NO_PROXY routing.

Tests / lint

  • Tests use the global fetch instead of requiring isomorphic-fetch.
  • .eslintrc.js declares the btoa/fetch/Headers/Request/Response globals (eslint 8's node env predates them).

yarn.lock: only the isomorphic-fetch, whatwg-fetch and @types/isomorphic-fetch entries are removed (node-fetch is still required transitively).

Comment thread packages/cli/test/fetch.test.js Fixed
@connorjclark
connorjclark added this pull request to stack #1212 November 12, 2026 04:15
@connorjclark
connorjclark merged commit a96dc88 into main Nov 12, 2026
17 checks passed
@connorjclark
connorjclark deleted the remove-isomorphic-fetch branch November 12, 2026 20:57
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