Skip to content

Commit b661ff2

Browse files
committed
fix(export): use ref for isExporting to avoid stale closure
Replace isExporting state in dependency array with useRef to prevent stale closure issues per hook best practices.
1 parent c6dc148 commit b661ff2

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

apps/sim/app/workspace/[workspaceId]/w/hooks/use-export-service.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useState } from 'react'
1+
import { useCallback, useRef, useState } from 'react'
22
import { createLogger } from '@/lib/logs/console/logger'
33
import { useNotificationStore } from '@/stores/notifications'
44

@@ -30,10 +30,11 @@ interface UseExportServiceProps {
3030
*/
3131
export function useExportService({ getWorkflowId, onSuccess }: UseExportServiceProps) {
3232
const [isExporting, setIsExporting] = useState(false)
33+
const isExportingRef = useRef(false)
3334
const addNotification = useNotificationStore((state) => state.addNotification)
3435

3536
const handleExportService = useCallback(async () => {
36-
if (isExporting) {
37+
if (isExportingRef.current) {
3738
return
3839
}
3940

@@ -43,6 +44,7 @@ export function useExportService({ getWorkflowId, onSuccess }: UseExportServiceP
4344
return
4445
}
4546

47+
isExportingRef.current = true
4648
setIsExporting(true)
4749
try {
4850
logger.info('Starting service export', { workflowId })
@@ -96,9 +98,10 @@ export function useExportService({ getWorkflowId, onSuccess }: UseExportServiceP
9698
logger.error('Error exporting service:', { error, workflowId })
9799
throw error
98100
} finally {
101+
isExportingRef.current = false
99102
setIsExporting(false)
100103
}
101-
}, [addNotification, getWorkflowId, isExporting, onSuccess])
104+
}, [addNotification, getWorkflowId, onSuccess])
102105

103106
return {
104107
isExporting,

0 commit comments

Comments
 (0)