akseljoonas HF Staff Claude Opus 4.6 (1M context) commited on
Commit
59b17bb
Β·
1 Parent(s): a61953e

fix: infinite re-render loop from Zustand selector returning new []

Browse files

The researchSteps selector created a new empty array on every call via
`?? []`, which fails Object.is equality and triggers a re-render loop.
Use a stable EMPTY_STEPS constant and return undefined from the selector
to let the ?? fallback use the stable reference.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

frontend/src/components/Chat/ToolCallGroup.tsx CHANGED
@@ -99,6 +99,9 @@ function ResearchSteps({ steps, isRunning }: { steps: string[]; isRunning: boole
99
  );
100
  }
101
 
 
 
 
102
  // ---------------------------------------------------------------------------
103
  // Hardware pricing ($/hr) β€” from HF Spaces & Jobs pricing
104
  // ---------------------------------------------------------------------------
@@ -397,8 +400,8 @@ export default function ToolCallGroup({ tools, approveTools }: ToolCallGroupProp
397
  const { setPanel, lockPanel, getJobUrl, getEditedScript } = useAgentStore();
398
  const researchSteps = useAgentStore(s => {
399
  const activeId = s.activeSessionId;
400
- return activeId ? (s.sessionStates[activeId]?.researchSteps ?? []) : [];
401
- });
402
  const { setRightPanelOpen, setLeftSidebarOpen } = useLayoutStore();
403
 
404
  // ── Batch approval state ──────────────────────────────────────────
 
99
  );
100
  }
101
 
102
+ // Stable reference to avoid infinite re-renders from Zustand selectors
103
+ const EMPTY_STEPS: string[] = [];
104
+
105
  // ---------------------------------------------------------------------------
106
  // Hardware pricing ($/hr) β€” from HF Spaces & Jobs pricing
107
  // ---------------------------------------------------------------------------
 
400
  const { setPanel, lockPanel, getJobUrl, getEditedScript } = useAgentStore();
401
  const researchSteps = useAgentStore(s => {
402
  const activeId = s.activeSessionId;
403
+ return activeId ? (s.sessionStates[activeId]?.researchSteps) : undefined;
404
+ }) ?? EMPTY_STEPS;
405
  const { setRightPanelOpen, setLeftSidebarOpen } = useLayoutStore();
406
 
407
  // ── Batch approval state ──────────────────────────────────────────