Skip to content

Commit

Permalink
Merge pull request #1255 from nyaruka/activity-timeout
Browse files Browse the repository at this point in the history
Clear activity timeout on unmount
  • Loading branch information
ericnewcomer authored Nov 23, 2024
2 parents e5996ce + 7f3eec4 commit 066344c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/components/flow/Flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { bindActionCreators } from 'redux';
import Plumber from 'services/Plumber';
import { DragSelection, DebugState } from 'store/editor';
import { RenderNode } from 'store/flowContext';
import { createEmptyNode, detectLoops, getOrderedNodes } from 'store/helpers';
import { createEmptyNode, detectLoops, fetchFlowActivity, getOrderedNodes } from 'store/helpers';
import { NodeEditorSettings } from 'store/nodeEditor';
import AppState from 'store/state';
import {
Expand Down Expand Up @@ -180,6 +180,9 @@ export class Flow extends React.PureComponent<FlowStoreProps, {}> {

public componentWillUnmount(): void {
this.Plumber.reset();
if ((window as any).activityTimeout) {
clearTimeout((window as any).activityTimeout);
}
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/store/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ interface Reflow {
}

// track if we have an active timeout before issuing a new one
let activityTimeout: any = null;
(window as any).activityTimeout = null;

export const getNodeWithAction = (nodes: RenderNodeMap, actionUUID: string): RenderNode => {
for (const nodeUUID of Object.keys(nodes)) {
Expand Down Expand Up @@ -698,11 +698,11 @@ export const fetchFlowActivity = (

dispatch(mergeEditorState(updates));

if (activityTimeout) {
window.clearTimeout(activityTimeout);
if ((window as any).activityTimeout) {
window.clearTimeout((window as any).activityTimeout);
}

activityTimeout = window.setTimeout(() => {
(window as any).activityTimeout = window.setTimeout(() => {
fetchFlowActivity(endpoint, dispatch, getState, uuid);
}, activityInterval);
}
Expand All @@ -711,11 +711,11 @@ export const fetchFlowActivity = (
// failure fetching activity, if this happens we stop trying to fetch more
});
} else {
if (activityTimeout) {
window.clearTimeout(activityTimeout);
if ((window as any).activityTimeout) {
window.clearTimeout((window as any).activityTimeout);
}

activityTimeout = window.setTimeout(() => {
(window as any).activityTimeout = window.setTimeout(() => {
fetchFlowActivity(endpoint, dispatch, getState, uuid);
}, 1000);
}
Expand Down

0 comments on commit 066344c

Please sign in to comment.