Skip to content

Commit

Permalink
Don't setTimeout in loadQuery in SSR
Browse files Browse the repository at this point in the history
Reviewed By: rbalicki2

Differential Revision: D22869273

fbshipit-source-id: 65da4e6d488690098e4436f3d364adf844ef4bcd
  • Loading branch information
rhagigi authored and facebook-github-bot committed Jul 31, 2020
1 parent 9fef901 commit 2da0325
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions packages/relay-experimental/loadQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
({dispose: cancelOnLoadCallback} = PreloadableQueryRegistry.onLoad(
moduleId,
preloadedModule => {
clearTimeout(loadQueryAstTimeoutId);
loadQueryAstTimeoutId != null && clearTimeout(loadQueryAstTimeoutId);
cancelOnLoadCallback();
const operation = createOperationDescriptor(
preloadedModule,
Expand All @@ -178,16 +178,18 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
executeWithSource(operation, source);
},
));
loadQueryAstTimeoutId = setTimeout(() => {
cancelOnLoadCallback();
const onTimeout = options?.onQueryAstLoadTimeout;
if (onTimeout) {
onTimeout();
}
// complete() the subject so that the observer knows no (additional) payloads
// will be delivered
normalizationSubject.complete();
}, LOAD_QUERY_AST_MAX_TIMEOUT);
if (!environment.isServer()) {
loadQueryAstTimeoutId = setTimeout(() => {
cancelOnLoadCallback();
const onTimeout = options?.onQueryAstLoadTimeout;
if (onTimeout) {
onTimeout();
}
// complete() the subject so that the observer knows no (additional) payloads
// will be delivered
normalizationSubject.complete();
}, LOAD_QUERY_AST_MAX_TIMEOUT);
}
}
} else {
const graphQlTaggedNode: GraphQLTaggedNode = (preloadableRequest: $FlowFixMe);
Expand Down

0 comments on commit 2da0325

Please sign in to comment.