Skip to content

Commit

Permalink
Allow onNewData to be called when unmounted, during SSR.
Browse files Browse the repository at this point in the history
PR #6216 introduced these isMounted guards, and was merged just before the
v3.0.0-rc.0 release. It appears (see #6386) that requiring the component
to be mounted is too restrictive, specifically when doing server-side
rendering, since the concept of mounting doesn't make sense without a DOM.
  • Loading branch information
benjamn committed Jun 4, 2020
1 parent a0844d7 commit cbab9a9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/react/data/QueryData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ export class QueryData<TData, TVariables> extends OperationData {
this.cleanup();
this.runLazy = true;
this.lazyOptions = options;
if (this.isMounted) this.onNewData();
if (this.isMounted || this.ssrInitiated()) {
this.onNewData();
}
};

private getExecuteResult(): QueryResult<TData, TVariables> {
Expand Down Expand Up @@ -291,7 +293,9 @@ export class QueryData<TData, TVariables> extends OperationData {
return;
}

if (this.isMounted) onNewData();
if (this.isMounted || this.ssrInitiated()) {
onNewData();
}
},
error: error => {
this.resubscribeToQuery();
Expand All @@ -303,7 +307,9 @@ export class QueryData<TData, TVariables> extends OperationData {
!equal(error, this.previousData.error)
) {
this.previousData.error = error;
if (this.isMounted) onNewData();
if (this.isMounted || this.ssrInitiated()) {
onNewData();
}
}
}
});
Expand Down

0 comments on commit cbab9a9

Please sign in to comment.