Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

tech(React19): die letzten Hook-Verstoesse in den grossen Dateien

Davidfdf81bceb3fe
diff --git a/src/components/create/experimental/CreateContext.tsx b/src/components/create/experimental/CreateContext.tsx
index 5449818c..1cc98991 100644
--- a/src/components/create/experimental/CreateContext.tsx
+++ b/src/components/create/experimental/CreateContext.tsx
@@ -305,7 +305,10 @@ export function CreateExpProvider({ children }: { children: ReactNode }) {
const out = await backendCall<{ lines?: string[] }>('comfyui_last_output').catch(() => null)
throw new Error(comfyStartupError(out?.lines))
}
- }, [checkConnection, repairComfyEnv, startAndAwait])
+ // `checkConnection` stand hier, ohne im Rumpf vorzukommen: aufgerufen wird
+ // es von `startAndAwait`, das selbst schon davon abhaengt. Der Eintrag war
+ // damit reine Dopplung derselben Invalidierung.
+ }, [repairComfyEnv, startAndAwait])
// Install a capability in place — mirrors the VHS one-click flow (#72):
// ensure ComfyUI runs, clone the custom node + pip install where one is
diff --git a/src/components/layout/AppShell.tsx b/src/components/layout/AppShell.tsx
index 98de791c..6e771f38 100644
--- a/src/components/layout/AppShell.tsx
+++ b/src/components/layout/AppShell.tsx
@@ -42,6 +42,12 @@ import { ShortcutsModal } from './ShortcutsModal'
import { CreditsExhaustedModal } from './CreditsExhaustedModal'
import { Titlebar } from './Titlebar'
+// Aus der Komponente herausgezogen: `new Set(STORE_KEYS)` entstand bei jedem
+// Render neu und war damit die instabile Referenz, wegen der der Restore-Effekt
+// seine eigene Abhaengigkeit nicht nennen konnte. STORE_KEYS ist ein
+// Modulkonstante, das Set also genauso konstant.
+const STORE_KEYS_SET = new Set(STORE_KEYS)
+
// The backup triad must never write %APPDATA%/store_backup.json before the
// restore decision — on a post-NSIS boot the first doBackup would otherwise
// snapshot the wiped localStorage over the only good backup. Resolved on every
@@ -204,7 +210,7 @@ export function AppShell() {
// The key lists and the snapshot builder live in lib/store-backup so the
// update path can ask for a backup too. It used to hand the process to the
// installer with whatever the 5 s interval last wrote (Bug A1, 2.6.7).
- const STORE_KEYS_SET = new Set(STORE_KEYS)
+ // (STORE_KEYS_SET steht jetzt auf Modulebene, siehe oben.)
// Feature FF: reserved key under which memory embeddings ride inside the RAG
// chunk backup file. Never collides with a real documentId (those are UUIDs).
@@ -391,7 +397,10 @@ export function AppShell() {
}
}, 100)
return () => clearInterval(waitForTauri)
- }, [])
+ // Beide Deps sind konstant: STORE_KEYS_SET liegt jetzt auf Modulebene,
+ // `updateSettings` ist eine Zustand-Action mit fester Referenz. Der
+ // Restore-Effekt bleibt damit exakt der Mount-Einmal-Effekt, der er war.
+ }, [updateSettings])
// Backup stores to %APPDATA% — three-pronged so chat history survives
// NSIS updates + abrupt process kills:
diff --git a/src/components/layout/Sidebar.tsx b/src/components/layout/Sidebar.tsx
index e961936c..27951b6d 100644
--- a/src/components/layout/Sidebar.tsx
+++ b/src/components/layout/Sidebar.tsx
@@ -286,7 +286,10 @@ export function Sidebar() {
tick()
const timer = setInterval(tick, 1000)
return () => clearInterval(timer)
- }, [passcodeExpiresAt, remoteEnabled])
+ // `regenerateToken` ist eine Store-Action mit fester Referenz (wie das
+ // `refreshDevices`/`hideQr` der Effekte darueber), der Countdown startet
+ // also weiterhin nur bei neuem Ablaufzeitpunkt oder Remote-Umschaltung neu.
+ }, [passcodeExpiresAt, regenerateToken, remoteEnabled])
return (
<AnimatePresence>
diff --git a/src/components/onboarding/Onboarding.tsx b/src/components/onboarding/Onboarding.tsx
index 5ee5b0e7..53295cee 100644
--- a/src/components/onboarding/Onboarding.tsx
+++ b/src/components/onboarding/Onboarding.tsx
@@ -1,4 +1,4 @@
-import { useState, useEffect } from 'react'
+import { useState, useEffect, useRef } from 'react'
import { withInstallerOutput } from '../../lib/error-text'
import { motion, AnimatePresence } from 'framer-motion'
import { Minus, Square, X as XIcon, ArrowRight, Download, Check, ChevronRight, Loader2, RefreshCw, ExternalLink, FolderOpen, Cpu } from 'lucide-react'
@@ -614,6 +614,11 @@ export function Onboarding() {
return () => clearInterval(timer)
}, [pythonStartTime])
+ /** Der Auto-Scan laeuft einmal pro Mount, sobald der comfyui-Schritt erreicht
+ * ist. Ref statt State: der Wert steuert keinen Render, sondern verhindert
+ * nur den Wiedereintritt in den Effekt. */
+ const comfyAutoDetectStarted = useRef(false)
+
// Auto-detect ComfyUI when entering the comfyui step. We mark the install
// as "ready" (=> Continue button) only when both `found` AND `complete`
// are true. A `found && !complete` carcass (P14) keeps the install option
@@ -623,7 +628,15 @@ export function Onboarding() {
// straight past this step, so `step` should never actually be 'comfyui'
// there — but never auto-detect/install ComfyUI on Mac regardless (hard
// rule: Mac local image/video is MLX only).
- if (step === 'comfyui' && !isMacOS() && !comfyFound && !comfyDetecting) {
+ if (step === 'comfyui' && !isMacOS() && !comfyAutoDetectStarted.current) {
+ // Die Wiedereintritts-Sperre steckte bisher in `!comfyFound &&
+ // !comfyDetecting`. Als Dependencies notiert waeren genau diese beiden
+ // eine Endlosschleife: der Mehrfach-Install-Zweig setzt `comfyFound`
+ // absichtlich wieder auf null und `finally` setzt `comfyDetecting` auf
+ // false — der Effekt haette sich damit selbst nachgetriggert und den
+ // Backend-Scan in Dauerschleife gefahren. Die Sperre ist Lauf-Zustand,
+ // kein Render-Zustand, und liegt deshalb in einer Ref.
+ comfyAutoDetectStarted.current = true
setComfyDetecting(true)
// First: enumerate ALL installs (Bug #3). When >1 we show a picker
// BEFORE auto-picking — preventing the ninjastic2008 trap where LU
diff --git a/src/components/settings/HardwareSettings.tsx b/src/components/settings/HardwareSettings.tsx
index ecac60c5..158fe72f 100644
--- a/src/components/settings/HardwareSettings.tsx
+++ b/src/components/settings/HardwareSettings.tsx
@@ -43,7 +43,10 @@ export function HardwareSettings() {
const [showRestartHint, setShowRestartHint] = useState(false)
const vendor = (settings.gpuVendor || 'auto') as GpuVendor
- const indices = settings.gpuIndices || []
+ // Das `|| []` erzeugte bei jedem Render ein frisches Array. Der Effekt unten
+ // haengt an `indices` und schickte deshalb bei JEDEM Render ein
+ // `set_gpu_selection` ans Backend, statt nur bei einer echten Aenderung.
+ const indices = useMemo(() => settings.gpuIndices || [], [settings.gpuIndices])
const detect = async () => {
setLoading(true)
diff --git a/src/components/settings/RemoteAccessSettings.tsx b/src/components/settings/RemoteAccessSettings.tsx
index 4097468e..53c9b529 100644
--- a/src/components/settings/RemoteAccessSettings.tsx
+++ b/src/components/settings/RemoteAccessSettings.tsx
@@ -18,7 +18,10 @@ export function RemoteAccessSettings() {
if (enabled) refreshDevices()
}, 10000)
return () => clearInterval(interval)
- }, [enabled])
+ // `refreshStatus`/`refreshDevices` sind Store-Actions aus dem create()-
+ // Initializer: ihre Referenz entsteht einmal und aendert sich nie. Der
+ // Effekt laeuft dadurch weiterhin nur bei einem Wechsel von `enabled`.
+ }, [enabled, refreshDevices, refreshStatus])
// Bug #10: the trash icon called an empty handler. Wire it up to the
// existing /remote-api/disconnect command and refetch afterwards so the
diff --git a/src/hooks/useChat.ts b/src/hooks/useChat.ts
index d1d7a3ec..955195ef 100644
--- a/src/hooks/useChat.ts
+++ b/src/hooks/useChat.ts
@@ -267,6 +267,12 @@ export function useChat() {
// Agent mode composition
const agentChat = useAgentChat()
+ // `useAgentChat()` gibt bei jedem Render ein frisches Objektliteral zurueck —
+ // das ist die instabile Referenz, wegen der `sendMessage` seine Abhaengigkeit
+ // nicht nennen konnte. Der einzige Teil davon, den `sendMessage` braucht, ist
+ // `sendAgentMessage`, und das ist ein useCallback mit leerer Dep-Liste, also
+ // ueber die Lebensdauer des Hooks stabil.
+ const { sendAgentMessage } = agentChat
const { extractAndSave } = useMemory()
// G29: a run outlives this hook instance when the chat view unmounts on a
@@ -360,13 +366,13 @@ export function useChat() {
return { pass: 1, intervalMs, task: rest || content, startedAt: Date.now() }
})()
: undefined
- return agentChat.sendAgentMessage(slash.expanded, images, {
+ return sendAgentMessage(slash.expanded, images, {
displayContent: content,
readOnly: slash.command.readOnly === true,
...(loop ? { loop } : {}),
})
}
- return agentChat.sendAgentMessage(content, images)
+ return sendAgentMessage(content, images)
}
// Group chat v1 (Nurse KillJoy): two to four models answer in turn in
@@ -406,7 +412,7 @@ export function useChat() {
// stripped from the curated list so a web/file turn can't call it.
const cloudMode = settings.appMode === 'cloud'
if (route && !(cloudMode && route.mediaHint)) {
- return agentChat.sendAgentMessage(content, images, {
+ return sendAgentMessage(content, images, {
curatedTools: cloudMode
? CHAT_TOOLS.filter((t) => t !== 'image_generate' && t !== 'video_generate')
: CHAT_TOOLS,
@@ -993,7 +999,11 @@ export function useChat() {
extractAndSave(content, contentRef.current, convId).catch(() => {})
}
}
- }, [])
+ // Alle drei Referenzen sind konstant: `extractAndSave` kommt aus dem
+ // Modul-Singleton MEMORY_API, `runGroupRound` ist ein useCallback mit
+ // leerer Dep-Liste, `sendAgentMessage` ebenfalls. `sendMessage` behaelt
+ // damit ueber die gesamte Hook-Lebensdauer dieselbe Identitaet wie vorher.
+ }, [extractAndSave, runGroupRound, sendAgentMessage])
const stopGeneration = useCallback(() => {
abortRef.current?.abort()
diff --git a/src/hooks/useCreate.ts b/src/hooks/useCreate.ts
index d51e7b30..bf3e9405 100644
--- a/src/hooks/useCreate.ts
+++ b/src/hooks/useCreate.ts
@@ -1444,7 +1444,12 @@ export function useCreate() {
// the haul instead of waiting for it to load).
if (renderEviction) void restoreChatBackendsAfterRender(renderEviction)
}
- }, [videoBackend, runCharacterTraining])
+ // `videoModelsList` ist State: seine Referenz wechselt nur, wenn
+ // setVideoModelsList wirklich eine neue Liste schreibt (fetchModels), und
+ // generateInner schreibt sie nicht. Der Callback wird also genau dann neu
+ // gebaut, wenn sich die Modellliste aendert — vorher las er sie aus einer
+ // veralteten Closure und leitete daraus den falschen `modelType` ab.
+ }, [videoBackend, runCharacterTraining, videoModelsList])
// Double-click idempotence: isGenerating only flips after the first await,
// so a second click racing the first must be blocked SYNCHRONOUSLY — two