Skip to content

The agent that grows with you

refactor(desktop): fold the font reseed latch into one dataUpdatedAt stamp

teknium192a6639e848f
diff --git a/apps/desktop/src/app/settings/chat-font-setting.tsx b/apps/desktop/src/app/settings/chat-font-setting.tsx
index f8a11d15e5d..ad54c455f9f 100644
--- a/apps/desktop/src/app/settings/chat-font-setting.tsx
+++ b/apps/desktop/src/app/settings/chat-font-setting.tsx
@@ -31,41 +31,31 @@ export function ChatFontSetting() {
const copy = t.settings.appearance
const { data: loadedConfig, dataUpdatedAt } = useHermesConfigRecord()
const [draft, setDraft] = useState<string | null>(null)
- const [profilePending, setProfilePending] = useState(false)
+ // dataUpdatedAt of the record the previous profile was looking at; the seed
+ // effect refuses to reseed while the query still carries that stamp. A
+ // structurally-shared refetch keeps the object reference but bumps the stamp.
+ const [staleStamp, setStaleStamp] = useState<null | number>(null)
const [saveVersion, setSaveVersion] = useState(0)
const saveVersionRef = useRef(0)
- const staleConfigStamp = useRef<null | number>(null)
const cancelPendingSave = () => {
saveVersionRef.current = 0
}
useEffect(() => {
- if (!loadedConfig || draft !== null || profilePending) {
+ if (!loadedConfig || draft !== null || dataUpdatedAt === staleStamp) {
return
}
const value = fontFamilyFromConfig(loadedConfig)
setDraft(value)
setChatFontFamilyFromConfig(value)
- }, [draft, loadedConfig, profilePending])
-
- // A profile switch invalidates without clearing the shared query. Wait for
- // its next successful result rather than comparing object identity: React
- // Query may structurally share an unchanged config record across refetches.
- // eslint-disable-next-line no-restricted-syntax -- query freshness stamp is a non-rendering latch
- useEffect(() => {
- if (profilePending && staleConfigStamp.current !== null && dataUpdatedAt !== staleConfigStamp.current) {
- staleConfigStamp.current = null
- setProfilePending(false)
- }
- }, [dataUpdatedAt, profilePending])
+ }, [dataUpdatedAt, draft, loadedConfig, staleStamp])
useOnProfileSwitch(() => {
saveVersionRef.current += 1
setDraft(null)
- staleConfigStamp.current = dataUpdatedAt
- setProfilePending(true)
+ setStaleStamp(dataUpdatedAt)
setSaveVersion(0)
setChatFontFamilyFromConfig('')
})
diff --git a/apps/desktop/src/app/settings/terminal-font-setting.tsx b/apps/desktop/src/app/settings/terminal-font-setting.tsx
index 94a8078c43a..cd092b960af 100644
--- a/apps/desktop/src/app/settings/terminal-font-setting.tsx
+++ b/apps/desktop/src/app/settings/terminal-font-setting.tsx
@@ -34,10 +34,11 @@ export function TerminalFontSetting() {
// the timestamp is the freshness proof because React Query can reuse the
// same config object when the next profile has identical settings.
const [draft, setDraft] = useState<string | null>(null)
- const [profilePending, setProfilePending] = useState(false)
+ // dataUpdatedAt of the record the previous profile was looking at; the seed
+ // effect refuses to reseed while the query still carries that stamp.
+ const [staleStamp, setStaleStamp] = useState<null | number>(null)
const [saveVersion, setSaveVersion] = useState(0)
const saveVersionRef = useRef(0)
- const staleConfigStamp = useRef<null | number>(null)
// Lexically outside every useEffect so async save callbacks can cancel the
// in-flight version without assigning to a ref inside an effect body.
@@ -46,28 +47,19 @@ export function TerminalFontSetting() {
}
useEffect(() => {
- if (!loadedConfig || draft !== null || profilePending) {
+ if (!loadedConfig || draft !== null || dataUpdatedAt === staleStamp) {
return
}
const value = fontFamilyFromConfig(loadedConfig)
setDraft(value)
setTerminalFontFamilyFromConfig(value)
- }, [draft, loadedConfig, profilePending])
-
- // eslint-disable-next-line no-restricted-syntax -- query freshness stamp is a non-rendering latch
- useEffect(() => {
- if (profilePending && staleConfigStamp.current !== null && dataUpdatedAt !== staleConfigStamp.current) {
- staleConfigStamp.current = null
- setProfilePending(false)
- }
- }, [dataUpdatedAt, profilePending])
+ }, [dataUpdatedAt, draft, loadedConfig, staleStamp])
useOnProfileSwitch(() => {
saveVersionRef.current += 1
setDraft(null)
- staleConfigStamp.current = dataUpdatedAt
- setProfilePending(true)
+ setStaleStamp(dataUpdatedAt)
setSaveVersion(0)
// Do not show the previous profile's font while the new profile loads.
setTerminalFontFamilyFromConfig('')