Skip to content
This repository was archived by the owner on Jun 16, 2022. It is now read-only.

Fix react-native fetch #26

Merged
merged 1 commit into from
Jul 10, 2018
Merged

Conversation

rodrigobdz
Copy link
Contributor

Importing isomorphic-fetch pollutes the global scope when fetch is already defined. Therefore, check if fetch is defined and dynamically import isomorphic-fetch if not.
PR for #22.

@giannif
Copy link
Collaborator

giannif commented Jul 10, 2018

@rodrigobdz this approach works for me. I suggested somewhere (maybe in slack with @cosmocochrane1 ?) just import the ponyfill but I'm not sure where that ended up

@cosmocochrane1
Copy link
Contributor

@giannif Yeah I remember you bringing this up - I did it for the analytics portion. Ill merge this in. @rodrigobdz Thanks!

@cosmocochrane1 cosmocochrane1 merged commit 5c7365d into Giphy:master Jul 10, 2018
@giannif
Copy link
Collaborator

giannif commented Jul 10, 2018

@cosmocochrane1 ok, if it worked for analytics then we probably should have done it here too, but nbd. If we ever switch to import statements we'll just use the ponyfill

@giannif
Copy link
Collaborator

giannif commented Jul 10, 2018

Wait, @cosmocochrane1 @rodrigobdz does this work? We're checking if fetch exists at compile time, no? I'm not familiar with the structure of this project

@rodrigobdz
Copy link
Contributor Author

rodrigobdz commented Jul 11, 2018

@giannif I'm using this solution in my project and it works.

We're checking if fetch exists at compile time, no?

What exactly do you mean by that? Babel does not evaluate the if statement at compile time.
Below is the output of Babel with the if statement as input.

Babel compile

@giannif
Copy link
Collaborator

giannif commented Jul 11, 2018

@rodrigobdz, yeah it's fine. I haven't used require in a while and thought for a second that webpack wouldn't bundle the dependency. I've spent all week redoing our chunking in our web app and had that mentality. I'm used to top-level imports and static analysis.

That said, I'm still in favor of the ponyfill approach since this is what they're for

Also, is there any reason why we use require? @cosmocochrane1? Not to go off topic.

@rodrigobdz
Copy link
Contributor Author

@giannif Using the fetch-ponyfill instead sounds good. isomorphic-fetch is no longer maintained.

@rodrigobdz rodrigobdz self-assigned this Jul 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants