fix: boucle infinie Maximum update depth dans useAutoTagging + toolbar
- use-auto-tagging: onQuotaExceeded via ref stable → n'invalide plus useCallback analyzeContent à chaque render parent - note-editor-context: filteredSuggestions et existingLabelsLower stabilisés avec useMemo (était recalculé sans memo → nouvelle ref à chaque render → état useMemo state se réexécutait → boucle) - deepseek.ts: generateTags via generateText (pas generateObject) pour éviter response_format:json_schema non supporté Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -25,6 +25,9 @@ export function useAutoTagging({ content, notebookId, enabled = true, onQuotaExc
|
||||
const previousNotebookId = useRef<string | null | undefined>(notebookId);
|
||||
// AbortController for cancelling in-flight requests
|
||||
const abortRef = useRef<AbortController | null>(null);
|
||||
// Stable ref for onQuotaExceeded — avoids re-creating analyzeContent on every render
|
||||
const onQuotaExceededRef = useRef(onQuotaExceeded);
|
||||
onQuotaExceededRef.current = onQuotaExceeded;
|
||||
|
||||
const analyzeContent = useCallback(async (contentToAnalyze: string, currentNotebookId?: string | null, currentLanguage?: string) => {
|
||||
if (!contentToAnalyze || contentToAnalyze.length < 10) {
|
||||
@@ -63,8 +66,8 @@ export function useAutoTagging({ content, notebookId, enabled = true, onQuotaExc
|
||||
if (controller.signal.aborted) return;
|
||||
|
||||
if (!response.ok) {
|
||||
if (response.status === 402 && onQuotaExceeded) {
|
||||
onQuotaExceeded();
|
||||
if (response.status === 402) {
|
||||
onQuotaExceededRef.current?.();
|
||||
}
|
||||
throw new Error('Error during analysis');
|
||||
}
|
||||
@@ -79,7 +82,7 @@ export function useAutoTagging({ content, notebookId, enabled = true, onQuotaExc
|
||||
setIsAnalyzing(false);
|
||||
}
|
||||
}
|
||||
}, [hasAiConsent, requestAiConsent, onQuotaExceeded]);
|
||||
}, [hasAiConsent, requestAiConsent]); // onQuotaExceeded via ref — stable
|
||||
|
||||
// Trigger on content change
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user