fix(desktop): key voice-fields autosave on the profile scope string
Parents (profile-config.tsx) build the `profile` scope as a fresh object literal on every render, so `useMemo(..., [profile])` produced a new cache writer each time and the autosave effect, which depends on both, tore down and re-armed its 550ms timer on every unrelated re-render. Key both on profileScopeKey(profile) — the same string the query cache already uses as the scope's identity — so only a real scope change re-arms them.
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
|
||||
import { getElevenLabsVoices, getHermesConfigSchema, type ProfileScope, saveHermesConfigRecord } from '@/hermes'
|
||||
import {
|
||||
getElevenLabsVoices,
|
||||
getHermesConfigSchema,
|
||||
type ProfileScope,
|
||||
profileScopeKey,
|
||||
saveHermesConfigRecord
|
||||
} from '@/hermes'
|
||||
import { useI18n } from '@/i18n'
|
||||
import { notifyError } from '@/store/notifications'
|
||||
import type { HermesConfigRecord } from '@/types/hermes'
|
||||
@@ -48,7 +54,13 @@ export function VoiceProviderFields({
|
||||
const { t } = useI18n()
|
||||
const keys = useMemo(() => voiceProviderKeys(section, providerKey), [section, providerKey])
|
||||
const { data: loadedConfig } = useHermesConfigRecord(profile)
|
||||
const writeConfigCache = useMemo(() => hermesConfigCacheWriter(profile), [profile])
|
||||
// Parents pass `profile` as a fresh object literal each render; keying the
|
||||
// writer and the autosave effect on its identity would re-arm the 550ms
|
||||
// timer on every unrelated re-render. Key on the scope string instead
|
||||
// (null when unscoped, which maps to the bare cache row).
|
||||
const scopeKey = profile == null ? null : profileScopeKey(profile)
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- scopeKey is the identity of `profile`
|
||||
const writeConfigCache = useMemo(() => hermesConfigCacheWriter(profile), [scopeKey])
|
||||
|
||||
const { data: schemaResponse } = useQuery({
|
||||
queryKey: ['hermes-config-schema'],
|
||||
@@ -94,8 +106,8 @@ export function VoiceProviderFields({
|
||||
}, 550)
|
||||
|
||||
return () => window.clearTimeout(timeout)
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- copy is stable; avoid re-scheduling autosave on locale change
|
||||
}, [config, profile, saveVersion, writeConfigCache])
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- copy is stable; `profile` is keyed by scopeKey; avoid re-scheduling autosave on locale change
|
||||
}, [config, scopeKey, saveVersion, writeConfigCache])
|
||||
|
||||
// ElevenLabs cloned/library voices from the live account, when available —
|
||||
// mirrors the Settings → Voice dynamic voice list.
|
||||
|
||||
Reference in New Issue
Block a user