From 5ec0a1eb64ec41d67c90a06c87b15aba5285da08 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sun, 31 May 2026 06:52:49 -0700 Subject: [PATCH] perf: move repository hooks flush cleanup to root ref (#4173) --- .../settings/RepositoryHooksSection.tsx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/renderer/src/components/settings/RepositoryHooksSection.tsx b/src/renderer/src/components/settings/RepositoryHooksSection.tsx index 6fd895be5fa..2e6fa2e6c3d 100644 --- a/src/renderer/src/components/settings/RepositoryHooksSection.tsx +++ b/src/renderer/src/components/settings/RepositoryHooksSection.tsx @@ -649,6 +649,17 @@ export function RepositoryHooksSection({ flushScriptDraft() }, [flushScriptDraft]) + // Why: unmount can happen before textareas blur; the root ref preserves the + // pending local-command save without paying for a cleanup-only Effect. + const flushScriptDraftOnUnmount = useCallback( + (node: HTMLElement | null): void => { + if (node === null) { + flushScriptDraft() + } + }, + [flushScriptDraft] + ) + const updateHookSettingsPolicyDraft = useCallback( (updates: HookSettingsPolicyDraft) => { persistHookSettings({ ...hookSettingsDraftRef.current, ...updates }) @@ -677,12 +688,6 @@ export function RepositoryHooksSection({ setHookSettingsDraft(next) }, [flushScriptDraft, onUpdateHookSettings, repo.id, repo.hookSettings, syncHookSettingsDraft]) - useEffect(() => { - return () => { - flushScriptDraft() - } - }, [flushScriptDraft]) - useEffect(() => { let cancelled = false const repoId = repo.id @@ -772,7 +777,7 @@ export function RepositoryHooksSection({ const [isAdvancedOpen, setIsAdvancedOpen] = useState(false) return ( -
+

Worktree Hooks