Files
dify/web/app/components/workflow/skill/hooks/use-skill-auto-save.ts
yyh f1d099d50d refactor: extract skill save context, stabilize mutation dependency, and deduplicate cache updates
Split SkillSaveContext and useSkillSaveManager into a separate file to
fix react-refresh/only-export-components lint error. Destructure
mutateAsync from useUpdateAppAssetFileContent for a stable callback
reference, preventing unnecessary useCallback cascade rebuilds. Extract
shared patchFileContentCache helper to unify setQueryData logic between
updateCachedContent and the collaboration event handler.
2026-02-03 21:09:35 +08:00

28 lines
529 B
TypeScript

import { useEventListener, useUnmount } from 'ahooks'
import { useSkillSaveManager } from './skill-save-context'
export function useSkillAutoSave(): void {
const { saveAllDirty } = useSkillSaveManager()
useUnmount(() => {
saveAllDirty()
})
useEventListener(
'visibilitychange',
() => {
if (document.visibilityState === 'hidden')
saveAllDirty()
},
{ target: document },
)
useEventListener(
'beforeunload',
() => {
saveAllDirty()
},
{ target: window },
)
}