Skip to content

Commit

Permalink
fix: fix time series data hook reactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbuss committed Nov 26, 2024
1 parent 7a3ecdc commit 289c135
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/core/src/data-module/TimeSeriesDataModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ export class TimeSeriesDataModule<Query extends DataStreamQuery> {
*/

const unsubscribe = () => {
this.unsubscribe(subscriptionId);
if (this.subscriptions.getSubscription(subscriptionId)) {
this.unsubscribe(subscriptionId);
}
};

const update = (subscriptionUpdate: SubscriptionUpdate<Query>) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 289c135

Please sign in to comment.