Skip to content

Commit 2da0325

Browse files
rhagigifacebook-github-bot
authored andcommittedJul 31, 2020
Don't setTimeout in loadQuery in SSR
Reviewed By: rbalicki2 Differential Revision: D22869273 fbshipit-source-id: 65da4e6d488690098e4436f3d364adf844ef4bcd
1 parent 9fef901 commit 2da0325

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed
 

‎packages/relay-experimental/loadQuery.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
169169
({dispose: cancelOnLoadCallback} = PreloadableQueryRegistry.onLoad(
170170
moduleId,
171171
preloadedModule => {
172-
clearTimeout(loadQueryAstTimeoutId);
172+
loadQueryAstTimeoutId != null && clearTimeout(loadQueryAstTimeoutId);
173173
cancelOnLoadCallback();
174174
const operation = createOperationDescriptor(
175175
preloadedModule,
@@ -178,16 +178,18 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
178178
executeWithSource(operation, source);
179179
},
180180
));
181-
loadQueryAstTimeoutId = setTimeout(() => {
182-
cancelOnLoadCallback();
183-
const onTimeout = options?.onQueryAstLoadTimeout;
184-
if (onTimeout) {
185-
onTimeout();
186-
}
187-
// complete() the subject so that the observer knows no (additional) payloads
188-
// will be delivered
189-
normalizationSubject.complete();
190-
}, LOAD_QUERY_AST_MAX_TIMEOUT);
181+
if (!environment.isServer()) {
182+
loadQueryAstTimeoutId = setTimeout(() => {
183+
cancelOnLoadCallback();
184+
const onTimeout = options?.onQueryAstLoadTimeout;
185+
if (onTimeout) {
186+
onTimeout();
187+
}
188+
// complete() the subject so that the observer knows no (additional) payloads
189+
// will be delivered
190+
normalizationSubject.complete();
191+
}, LOAD_QUERY_AST_MAX_TIMEOUT);
192+
}
191193
}
192194
} else {
193195
const graphQlTaggedNode: GraphQLTaggedNode = (preloadableRequest: $FlowFixMe);

0 commit comments

Comments
 (0)
Please sign in to comment.