{
subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
}), [obsQuery]);
- if (this.renderPromises) {
- this.renderPromises.registerSSRObservable(obsQuery);
+ const ssrAllowed = !(
+ this.queryHookOptions.ssr === false ||
+ this.queryHookOptions.skip
+ );
- const ssrAllowed = !(
- this.queryHookOptions.ssr === false ||
- this.queryHookOptions.skip
- );
+ if (this.renderPromises && ssrAllowed) {
+ this.renderPromises.registerSSRObservable(obsQuery);
- if (ssrAllowed && obsQuery.getCurrentResult().loading) {
+ if (obsQuery.getCurrentResult().loading) {
// TODO: This is a legacy API which could probably be cleaned up
this.renderPromises.addObservableQueryPromise(obsQuery);
}
diff --git a/src/react/ssr/__tests__/useQuery.test.tsx b/src/react/ssr/__tests__/useQuery.test.tsx
index 0e5aacb584b..7b40ef7131a 100644
--- a/src/react/ssr/__tests__/useQuery.test.tsx
+++ b/src/react/ssr/__tests__/useQuery.test.tsx
@@ -184,6 +184,56 @@ describe('useQuery Hook SSR', () => {
});
});
+ it('should render SSR tree rendering if `skip` option is `true` for only one instance of the query', async () => {
+ let renderCount = 0;
+
+ const AnotherComponent = () => {
+ const {
+ loading,
+ data,
+ } = useQuery(CAR_QUERY, { skip: false });
+
+ renderCount += 1;
+
+ if (!loading) {
+ expect(data).toEqual(CAR_RESULT_DATA);
+ const { make, model, vin } = data.cars[0];
+ return (
+
+ {make}, {model}, {vin}
+
+ );
+ }
+
+ return null;
+ };
+
+ const Component = () => {
+ const {
+ loading,
+ data,
+ } = useQuery(CAR_QUERY, { skip: true });
+ renderCount += 1;
+
+ expect(loading).toBeFalsy();
+ expect(data).toBeUndefined();
+
+ return ;
+ };
+
+ const app = (
+
+
+
+ );
+
+ return renderToStringWithData(app).then(result => {
+ expect(renderCount).toBe(4);
+ expect(result).toMatch(/Audi/);
+ expect(result).toMatch(/RS8/);
+ });
+ });
+
it('should return data written previously to cache during SSR pass if using cache-only fetchPolicy', async () => {
const cache = new InMemoryCache({
typePolicies: {