Skip to content

Commit

Permalink
Avoid registering QueryPromise when skip is true during SSR (#7310)
Browse files Browse the repository at this point in the history
  • Loading branch information
izumin5210 authored Nov 18, 2020
1 parent fd9b4a0 commit 5184845
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
- Allow optional arguments in `keyArgs: [...]` arrays for `InMemoryCache` field policies. <br/>
[@benjamn](https://github.com/benjamn) in [#7109](https://github.com/apollographql/apollo-client/pull/7109)

- Avoid registering `QueryPromise` when `skip` is `true` during server-side rendering. <br/>
[@izumin5210](https://github.com/izumin5210) in [#7310](https://github.com/apollographql/apollo-client/pull/7310)

## Apollo Client 3.2.7

## Bug Fixes
Expand Down
3 changes: 2 additions & 1 deletion src/react/data/QueryData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ export class QueryData<TData, TVariables> extends OperationData {
};

private getExecuteSsrResult() {
const ssrDisabled = this.getOptions().ssr === false;
const { ssr, skip } = this.getOptions();
const ssrDisabled = ssr === false || skip;
const fetchDisabled = this.refreshClient().client.disableNetworkFetches;

const ssrLoading = {
Expand Down
25 changes: 25 additions & 0 deletions src/react/ssr/__tests__/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,29 @@ describe('useQuery Hook SSR', () => {
});
}
);

it('should skip SSR tree rendering if `skip` option is `true`', async () => {
let renderCount = 0;
const Component = () => {
const { data, loading } = useQuery(CAR_QUERY, { skip: true });
renderCount += 1;

if (!loading) {
const { make } = data.cars[0];
return <div>{make}</div>;
}
return null;
};

const app = (
<MockedProvider mocks={CAR_MOCKS}>
<Component />
</MockedProvider>
);

return renderToStringWithData(app).then((result) => {
expect(renderCount).toBe(1);
expect(result).toEqual('');
});
});
});

0 comments on commit 5184845

Please sign in to comment.