[UI] Fix Status Check Leak (#853)

This commit is contained in:
Johannes Batzill 2023-12-01 01:30:02 +00:00 committed by Harness
parent 99c27f8fac
commit b4a1c293dc
1 changed files with 9 additions and 3 deletions

View File

@ -105,15 +105,21 @@ export function usePRChecksDecision({
}, [data]) // eslint-disable-line react-hooks/exhaustive-deps }, [data]) // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => { useEffect(() => {
let tornDown = false
const pollingFn = () => { const pollingFn = () => {
if (repoMetadata?.path && pullRequestMetadata?.source_sha && !complete) { if (repoMetadata?.path && pullRequestMetadata?.source_sha && !complete && !tornDown) {
refetch().then(() => { // 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) interval = window.setTimeout(pollingFn, POLLING_INTERVAL)
}) })
} }
} }
let 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 }, [repoMetadata?.path, pullRequestMetadata?.source_sha, complete]) // eslint-disable-line react-hooks/exhaustive-deps
return { return {