Skip to content

RestLink causes network calls to be executed much later #286

Open
@kyeb-stripe

Description

Hi! We've run into a performance issue with apollo-link-rest.

Recently, we started hoisting our queries to the top of our pages so that the network fetch gets kicked off before the initial render. If the fetch can be called before ~100ms of React rendering, the page will be finished loading ~100ms faster.

Unfortunately, apollo-link-rest seems to have an issue where this is impossible - even after hoisting queries to the top level, the fetch still doesn't get kicked off until after all of the initial rendering. It seems to be because the network call is somehow being made asynchronously, and the browser finishes executing the render before coming back and actually firing the network call.

Simple repro:

Edit quiet-morning-b522c

  1. Open your browser's developer tools
  2. Toggle the query
  3. Observe that on hitting the debugger statement for the first time (immediately after the useQuery), the network request has not yet been kicked off

We've narrowed down the cause of the async-ness to #138. If you change the version of apollo-link-rest to v0.4.4 in the above CodeSandbox, then you can observe that on hitting the debugger statement for the first time, the network request has already been kicked off (yay)!

Internally, we've had to fork apollo-link-rest and revert #138 (we don't need support for mixed queries, and need the performance). Happy to discuss further if I can help debug at all!

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions