perf: move repository hooks flush cleanup to root ref (#4173)

This commit is contained in:
Neil
2026-05-31 06:52:49 -07:00
committed by GitHub
parent 4e8c023a55
commit 5ec0a1eb64
@@ -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 (
<section className="space-y-6">
<section ref={flushScriptDraftOnUnmount} className="space-y-6">
<div className="space-y-1">
<h2 className="text-sm font-semibold">Worktree Hooks</h2>
<p className="text-xs text-muted-foreground">