From 289c135c0097a7a932ffde142e38b373bd5f659c Mon Sep 17 00:00:00 2001 From: jmbuss Date: Mon, 25 Nov 2024 15:32:41 -0700 Subject: [PATCH] fix: fix time series data hook reactivity --- packages/core/src/data-module/TimeSeriesDataModule.ts | 4 +++- .../src/hooks/useTimeSeriesData/useTimeSeriesData.ts | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/core/src/data-module/TimeSeriesDataModule.ts b/packages/core/src/data-module/TimeSeriesDataModule.ts index 934092a08..f35510530 100644 --- a/packages/core/src/data-module/TimeSeriesDataModule.ts +++ b/packages/core/src/data-module/TimeSeriesDataModule.ts @@ -187,7 +187,9 @@ export class TimeSeriesDataModule { */ const unsubscribe = () => { - this.unsubscribe(subscriptionId); + if (this.subscriptions.getSubscription(subscriptionId)) { + this.unsubscribe(subscriptionId); + } }; const update = (subscriptionUpdate: SubscriptionUpdate) => diff --git a/packages/react-components/src/hooks/useTimeSeriesData/useTimeSeriesData.ts b/packages/react-components/src/hooks/useTimeSeriesData/useTimeSeriesData.ts index 080cc2b60..794d2715c 100644 --- a/packages/react-components/src/hooks/useTimeSeriesData/useTimeSeriesData.ts +++ b/packages/react-components/src/hooks/useTimeSeriesData/useTimeSeriesData.ts @@ -108,6 +108,15 @@ export const useTimeSeriesData = ({ const queriesString = JSON.stringify(scrubbedQueries); useEffect(() => { + /** + * Reset datastreams whenever the query changes so that + * old datastreams are cleared away. This is important if + * the new query does not end up calling next for some + * reason. In that case, the datastreams state would still + * represent the previous queries data. + */ + setDataStreams([]); + const id = uuid(); providerIdRef.current = id; const provider = ProviderStore.set(