From 7f2b63b39c13dd16ef85bbc3868e09f45397ab66 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sun, 31 May 2026 08:29:24 -0700 Subject: [PATCH] perf: move branch prompt cleanup to setting ref (#4211) --- .../AutoRenameBranchFromWorkSetting.tsx | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/renderer/src/components/settings/AutoRenameBranchFromWorkSetting.tsx b/src/renderer/src/components/settings/AutoRenameBranchFromWorkSetting.tsx index 6f5429273c8..3e0864c5059 100644 --- a/src/renderer/src/components/settings/AutoRenameBranchFromWorkSetting.tsx +++ b/src/renderer/src/components/settings/AutoRenameBranchFromWorkSetting.tsx @@ -1,7 +1,7 @@ /* eslint-disable max-lines -- Why: the setting owns one collapsed form with queued writes, model selection, and prompt draft state. Splitting the tiny subcontrols would make the settings write flow harder to audit. */ -import { useEffect, useMemo, useRef, useState } from 'react' +import { useCallback, useEffect, useMemo, useRef, useState } from 'react' import { ChevronDown } from 'lucide-react' import type { GlobalSettings } from '../../../../shared/types' import type { @@ -158,12 +158,16 @@ export function AutoRenameBranchFromWorkSetting({ onBranchPromptDirtyChange?.(branchNamePromptDirty) }, [branchNamePromptDirty, onBranchPromptDirtyChange]) - useEffect( - () => () => { - onBranchPromptDirtyChange?.(false) - }, - [onBranchPromptDirtyChange] - ) + const onBranchPromptDirtyChangeRef = useRef(onBranchPromptDirtyChange) + onBranchPromptDirtyChangeRef.current = onBranchPromptDirtyChange + const setSettingRootRef = useCallback((node: HTMLDivElement | null): void => { + if (node !== null) { + return + } + // Why: Settings owns the global unsaved-branch-prompt guard; reset it + // when this setting detaches without a passive cleanup-only Effect. + onBranchPromptDirtyChangeRef.current?.(false) + }, []) const resolvedAgentId = resolveCommitMessageAgentChoice( config.agentId, @@ -302,7 +306,7 @@ export function AutoRenameBranchFromWorkSetting({ forceVisible={forceVisible || branchNamePromptDirty || advancedSearchOpen} className="space-y-3 py-2" > -
+