tenseleyflow/claudex / b85ff40

Browse files

fix: hoist claudeArgs useMemo above early returns (rules of hooks)

Authored by espadonne
SHA
b85ff40a5cfc078aa9fd6355391f7b1b6abe81a4
Parents
dfb80df
Tree
d4ee847

1 changed file

StatusFile+-
M src/components/ViewerPane.tsx 15 10
src/components/ViewerPane.tsxmodified
@@ -36,6 +36,21 @@ export function ViewerPane() {
3636
     return false;
3737
   }, [detail, inFlightTurns]);
3838
 
39
+  // Build the claude argv for terminal mode. Must live above the
40
+  // early returns below — React's rules of hooks require every
41
+  // hook to run in the same order on every render, so an early
42
+  // return followed by a later `useMemo` triggers the
43
+  // "Rendered more hooks than during the previous render" crash.
44
+  const claudeArgs = useMemo<string[]>(() => {
45
+    if (!detail) return [];
46
+    const { summary } = detail;
47
+    if (summary.source === "archive") return [];
48
+    if (summary.id.startsWith("pending-")) {
49
+      return ["--session-id", summary.id.replace(/^pending-/, "")];
50
+    }
51
+    return ["--resume", summary.id];
52
+  }, [detail]);
53
+
3954
   if (loading) {
4055
     return (
4156
       <Shell subtitle={selectedSessionId ?? ""}>
@@ -61,16 +76,6 @@ export function ViewerPane() {
6176
   const isArchive = summary.source === "archive";
6277
   const mode = viewerMode.get(summary.id) ?? "cards";
6378
   const hasLivePty = ptyIds.has(summary.id);
64
-  // Pending sessions strip their `pending-` prefix before being
65
-  // passed to `claude --session-id`. Disk sessions use their id
66
-  // directly with `--resume`.
67
-  const claudeArgs = useMemo<string[]>(() => {
68
-    if (isArchive) return [];
69
-    if (summary.id.startsWith("pending-")) {
70
-      return ["--session-id", summary.id.replace(/^pending-/, "")];
71
-    }
72
-    return ["--resume", summary.id];
73
-  }, [isArchive, summary.id]);
7479
 
7580
   return (
7681
     <Shell