remix icon indicating copy to clipboard operation
remix copied to clipboard

fetch() doesn't return correct Response type

Open christian-reichart opened this issue 3 years ago • 7 comments
trafficstars

What version of Remix are you using?

1.7.2

Steps to Reproduce

Inside the remix project try

const a = await fetch('https://google.com')
console.log('a instanceof Response: ', a instanceof Response) // -> false

This probably has to do with this commit: https://github.com/remix-run/remix/commit/25b4c83b10c5bc4d84ea81407e7de1a0e4f43df4#diff-87ec1c3c130fe3481b9f1c542b1d8a53548882d33c73c68b894fd442d606afc0

A current workaround I found thanks to @milamer is to include

import { Response } from '@remix-run/web-fetch'

in the file.

Expected Behavior

instanceof Response should be true

Actual Behavior

instanceof Response is false

christian-reichart avatar Oct 20 '22 15:10 christian-reichart

Hi @christian-reichart, where are you importing fetch from?

machour avatar Oct 31 '22 09:10 machour

Hi @machour , I don't import it specifically, so it's the global fetch.

christian-reichart avatar Oct 31 '22 09:10 christian-reichart

Any reason why you're not using remix's fetch?

import { fetch } from "@remix-run/node";

machour avatar Oct 31 '22 12:10 machour

Thanks for your response @machour ! Correct me if I'm wrong but I was under the impression that Remix is supposed to let you use fetch and Response without any import. https://remix.run/docs/en/v1/other-api/fetch Is the documentation outdated?

christian-reichart avatar Nov 01 '22 09:11 christian-reichart

Now I'm the one confused 😅 I'll circle back with the team on this point and let you know what's the right approach, and will update the docs if necessary.

In the meantime, does using fetch from @remix-run/node fix your original issue?

You might also be interested in reading the "Moving closer to The Platform™" part from the 1.5.0 release notes : https://github.com/remix-run/remix/releases/tag/v1.5.0

machour avatar Nov 01 '22 09:11 machour

@machour I have run into this issue with reimix-run/node and external libraries that use globals and instanceof Response.

I have been able to work around but latest is in a nested dependency using oauth4webapi

Any thoughts from the team yet on how to fix the inconsistent globals?

In the router they worked around it as well for more context

https://github.com/remix-run/react-router/pull/9690

Although if it is an issue with esm vs cjs not sure what the solution could be

acoreyj avatar Jan 13 '23 13:01 acoreyj

Found fix and made a merge request.

Here is patch that can be used with patch-package https://gist.github.com/acoreyj/37eff1fdc459dbea31515d5d40be7b35

acoreyj avatar Jan 14 '23 14:01 acoreyj

Should be closed by https://github.com/remix-run/remix/pull/7109

jacob-ebey avatar Aug 09 '23 00:08 jacob-ebey

🤖 Hello there,

We just published version v0.0.0-nightly-a179aa7-20230809 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

github-actions[bot] avatar Aug 09 '23 07:08 github-actions[bot]

🤖 Hello there,

We just published version v0.0.0-nightly-b1149bb-20230810 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

github-actions[bot] avatar Aug 10 '23 07:08 github-actions[bot]