Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.9.7 switching fetch in HttpLink to Axios triples speed #11770

Closed
billnbell2 opened this issue Apr 9, 2024 · 8 comments
Closed

3.9.7 switching fetch in HttpLink to Axios triples speed #11770

billnbell2 opened this issue Apr 9, 2024 · 8 comments
Labels
🏓 awaiting-contributor-response requires input from a contributor ℹ needs-more-info Needs more information to determine root cause

Comments

@billnbell2
Copy link

Issue Description

I switched fetch in HttpLink to Axios and the speed went from 5-7 seconds to 1 second! NEXT JS

WHY
?

Link to Reproduction

NO

Reproduction Steps

NOPE

@apollo/client version

3.9.7

@phryneas
Copy link
Member

phryneas commented Apr 9, 2024

It's hard to tell anything here without seeing what exactly you did - please show us some code :)

Also, how did you measure this speed increase? Is this in RSC, SSR or in the Browser? How big is your response?

I think we'll generally need a bit more context here :)

@jerelmiller jerelmiller added 🏓 awaiting-contributor-response requires input from a contributor ℹ needs-more-info Needs more information to determine root cause labels Apr 9, 2024
Copy link
Contributor

We're closing this issue now but feel free to ping the maintainers or open a new issue if you still need support. Thank you!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 10, 2024
@billnbell2
Copy link
Author

billnbell2 commented May 10, 2024

Here is some code.

It is pretty self explanatory though. Switch Apollo-CLient to use cross-fetch.

Here -

import fetch from 'cross-fetch';

export const client = (
  showError: (str?: string) => void = (_str?: string) => {}
) =>
  new ApolloClient({
    defaultOptions,
    link: from([
      authLink,
      retryLink,
      errorLink(showError),
        createHttpLink({
            uri: process.env.NEXT_PUBLIC_GRAPHQL_URL,
            fetch,
          }),
    ]),
    cache,
  });

@jerelmiller
Copy link
Member

@billnbell2 appreciate the code, but I'm not sure what you're looking for from us?

@billnbell2
Copy link
Author

billnbell2 commented May 10, 2024

Why do I need to use cross-fetch ?

If I leave it the default it takes Apollo Client 1-2 seconds per calls, when I use cross-fetch we are consistently at 200ms. Same exact call.

@billnbell2
Copy link
Author

Can you try it yourself and see if you get similar perf gains?

@jerelmiller
Copy link
Member

jerelmiller commented May 10, 2024

You are absolutely free to use whatever fetch implementation works for you. We're just using the built-in global fetch function available in your environment.

The only thing I can think might be happening here is that perhaps something is patching fetch in your environment and causing the perf issues on your end. Your code sample implies you're using Next.js which does fetch patching to add cache behavior to it. In fact, this was something that was recently reverted in React itself. Perhaps you're running into something here?

To be honest, even if this weren't it, we wouldn't make any current changes as using the global fetch function means we don't need additional dependencies which adds bundle size. Again, feel free to use cross-fetch if you'd like instead. I'd start however by taking a look at your global fetch function to see if there is something patching it first. You might be able to avoid the cross-fetch dependency yourself if need be. You can find out more about how Next.js patches it in their docs.

Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🏓 awaiting-contributor-response requires input from a contributor ℹ needs-more-info Needs more information to determine root cause
Projects
None yet
Development

No branches or pull requests

3 participants