From cbab9a9ac08ea0a9f5ce955f796f4f79898f2f5e Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Thu, 4 Jun 2020 17:37:51 -0400 Subject: [PATCH] Allow onNewData to be called when unmounted, during SSR. 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. --- src/react/data/QueryData.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/react/data/QueryData.ts b/src/react/data/QueryData.ts index 2fc8fdf14b2..64374f1d2a5 100644 --- a/src/react/data/QueryData.ts +++ b/src/react/data/QueryData.ts @@ -133,7 +133,9 @@ export class QueryData 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 { @@ -291,7 +293,9 @@ export class QueryData extends OperationData { return; } - if (this.isMounted) onNewData(); + if (this.isMounted || this.ssrInitiated()) { + onNewData(); + } }, error: error => { this.resubscribeToQuery(); @@ -303,7 +307,9 @@ export class QueryData extends OperationData { !equal(error, this.previousData.error) ) { this.previousData.error = error; - if (this.isMounted) onNewData(); + if (this.isMounted || this.ssrInitiated()) { + onNewData(); + } } } });