question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG]: useLazyQuery + SSR hangs the rendering process with version 3.5.x

See original GitHub issue

Intended outcome:

Render a component that contains a useLazyQuery hook.

Actual outcome:

The rendering process hangs even if the component is returned.

How to reproduce the issue:

Clone the following repo: https://github.com/simplecommerce/meteor-graphql-app

Make sure meteor is installed and execute meteor npm install and meteor run. It will run on port 3000.

Load the site, it should render with no issues. It runs on version 3.4.7 of @apollo/client.

Now stop the instance and execute meteor npm install @apollo/client@3.5.4 and run the instance again. Now try to load the site, it will hang and eventually time out.

If you go to https://github.com/simplecommerce/meteor-graphql-app/blob/master/imports/ui/Info.jsx and place a return "test"; before the useLazyQuery it will render, but if you place it after, it won’t.

I tried to console.log the variables, loading, error, etc, and they all seem ok at first glance, so something else seems to be causing it to time out or hang.

I also tried versions 3.5.0 up to 3.5.4 and the same issue occurs.

Versions

  System:
    OS: Linux 4.15 Ubuntu 18.04.1 LTS (Bionic Beaver)
  Binaries:
    Node: 12.15.0 - ~/.nvm/versions/node/v12.15.0/bin/node
    npm: 6.13.4 - ~/.nvm/versions/node/v12.15.0/bin/npm
  npmPackages:
    @apollo/client: ^3.5.4 => 3.5.4
    apollo-server: ^2.25.2 => 2.25.2

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:20
  • Comments:17 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
redeyes2015commented, Feb 9, 2022

I met this issue recently. However, it seems adding ssr: false in the options of useLazyQuery would mitigate this issue. Like: const [doQuery, { data }] = useLazyQuery(GQL_DOC, { ssr: false });

This is odd, since useLazyQuery should be skipped in SSR by nature. Could anyone check this?

Edit: v3.5.7 just released hours ago, and the situation still the same.

Edit2: I just found src/react/ssr/__tests__/useLazyQuery.test.tsx and this issue can be reproduced in test environment:

  it('should render', () => {
    const link = mockSingleLink({
      request: { query: CAR_QUERY },
      result: { data: CAR_RESULT_DATA }
    });

    const client = new ApolloClient({
      cache: new InMemoryCache(),
      link,
      ssrMode: true
    });

    const Component = () => {
      const [, { loading, called, data }] = useLazyQuery(CAR_QUERY); // this will cause render time out
      // const [, { loading, called, data }] = useLazyQuery(CAR_QUERY, { ssr: false }); // this will render

      expect(called).toEqual(false);
      expect(loading).toEqual(false);
      expect(data).toEqual(undefined);

      return null;
    };

    const app = (
      <ApolloProvider client={client}>
        <Component />
      </ApolloProvider>
    );

    return renderToStringWithData(app).then(markup => {
      console.log({ markup });
    });
  });

Edit 3: Checked v3.5.8, v3.6.0-beta.5, and main (43883b33e): all of them have the same behavior mentioned above.

9reactions
jclvicerracommented, Nov 25, 2021

We are also experiencing the same issues using the useLazyQuery on our SSR pages.

When on Netlify, the SSR fails that uses useLazyQuery and would return error decoding lambda response: invalid status code returned from lambda: 0.

Downgrading to v3.4.17 seems to fix the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hooks - Apollo GraphQL Docs
One way to access the configured Apollo Client instance directly is to create an ApolloConsumer component and provide a render prop function as...
Read more >
apollo-cache-inmemory - Awesome JS
IMPORTANT Version 3.7.3 is not installable due to an issue with our release process which caused a mismatch between package-lock.json and package.json ...
Read more >
'loading' remains true when loading data with 'useQuery' using ...
I'm trying to fetch data using Apollo Client useQuery in React Native, but loading hangs ...
Read more >
@apollo/client | Yarn - Package Manager
Important: This documentation covers modern versions of Yarn. For 1.x docs, see classic.yarnpkg.com. Yarn.
Read more >
How to use the react-apollo.renderToStringWithData function ...
cache, }); // to be used by react-apollo const component = ( <ApolloProvider ... sheet={sheet.instance}> <ErrorOverlay> Server-side rendering error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found