Skip to content

fetch(...) instanceof Response fails after installGlobals()  #7059

@jeeyoungk

Description

@jeeyoungk

What version of Remix are you using?

1.19

Are all your remix dependencies & dev-dependencies using the same version?

  • Yes

Steps to Reproduce

Many libraries depend resp instanceof Response to return true; https://github.com/panva/oauth4webapi/blob/170f44e2f7c7da60feb8a654871c56fc0a741e6b/src/index.ts#L1513 is one of such a library. However, after Remix patches the global fetch instance, this no longer holds.

I've tested this with the following three scenarios:

  1. vanilla environment in node 20 (works)
  2. remix-run/web-fetch (works)
  3. remix-run/node (doesn't work)
{
  // correct behavior
  console.log((await fetch("http://example.com")) instanceof Response);
}
{
  // also correct behavior
  const i = await import("@remix-run/web-fetch");
  console.log((await i.fetch("http://example.com")) instanceof i.Response);
}
{
  // incorrect behavior; fails.
  const j = await import("@remix-run/node");
  console.log((await j.fetch("http://example.com")) instanceof j.Response);
}

The last one is important, as this is the version of globals that's installed via installGlobals.

Expected Behavior

(await fetch(...)) instanceof Response should return true for fetch and Response exposed by remix-run/node.

Actual Behavior

as the exposed types from remix-run/node is NodeResponse, the instanceof fails.

❓ Question

What I don't particularly understand is why we have the NodeRequest and NodeResponse. This is the reason why it's causing this type mismatch issue; these classes seem to be serving very little purpose. We're actually not instantiating these types at all, most of the (non-test) code is using ... as NodeResponse to coerce types. Can we just eliminate them, and expose @remix-run/web-fetch classes and types directly?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions