From b4a1c293dc923c247eb5761ee08a60c35544d424 Mon Sep 17 00:00:00 2001 From: Johannes Batzill Date: Fri, 1 Dec 2023 01:30:02 +0000 Subject: [PATCH] [UI] Fix Status Check Leak (#853) --- web/src/hooks/usePRChecksDecision.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/web/src/hooks/usePRChecksDecision.tsx b/web/src/hooks/usePRChecksDecision.tsx index de475f5e3..b41c660f3 100644 --- a/web/src/hooks/usePRChecksDecision.tsx +++ b/web/src/hooks/usePRChecksDecision.tsx @@ -105,15 +105,21 @@ export function usePRChecksDecision({ }, [data]) // eslint-disable-line react-hooks/exhaustive-deps useEffect(() => { + let tornDown = false const pollingFn = () => { - if (repoMetadata?.path && pullRequestMetadata?.source_sha && !complete) { - refetch().then(() => { + if (repoMetadata?.path && pullRequestMetadata?.source_sha && !complete && !tornDown) { + // TODO: fix racing condition where an ongoing refetch of the old sha overwrites the new one. + // TEMPORARY SOLUTION: set debounce to 1 second to reduce likelyhood + refetch({ debounce: 1 }).then(() => { interval = window.setTimeout(pollingFn, POLLING_INTERVAL) }) } } let interval = window.setTimeout(pollingFn, POLLING_INTERVAL) - return () => window.clearTimeout(interval) + return () => { + tornDown = true + window.clearTimeout(interval) + } }, [repoMetadata?.path, pullRequestMetadata?.source_sha, complete]) // eslint-disable-line react-hooks/exhaustive-deps return {