Description
disabledTools is a string[] from a Jotai atom. Multiple .includes() and .every() calls check membership inside the tool UI rendering in thread.tsx (~lines 849, 860, 906-911, 981, 1013, 1107, 1144). Each .includes() is O(n) per check, and this runs on every render of the thread component.
Vercel React Best Practices Rule: js-set-map-lookups (7.11)
File to change
surfsense_web/components/assistant-ui/thread.tsx
What to do
- After reading the atom, create a memoized Set:
const disabledTools = useAtomValue(disabledToolsAtom);
const disabledToolsSet = useMemo(() => new Set(disabledTools), [disabledTools]);
- Replace all
.includes() calls:
// Before
disabledTools.includes(tool.name)
// After
disabledToolsSet.has(tool.name)
- Replace all
.every() calls that check membership:
// Before
toolNames.every(name => disabledTools.includes(name))
// After
toolNames.every(name => disabledToolsSet.has(name))
Acceptance criteria
disabledToolsSet is a useMemo-wrapped Set
- All
.includes()/.every() calls on disabledTools are replaced with .has() on the Set
- Tool enable/disable toggles still work correctly
Description
disabledToolsis astring[]from a Jotai atom. Multiple.includes()and.every()calls check membership inside the tool UI rendering inthread.tsx(~lines 849, 860, 906-911, 981, 1013, 1107, 1144). Each.includes()is O(n) per check, and this runs on every render of the thread component.Vercel React Best Practices Rule:
js-set-map-lookups(7.11)File to change
surfsense_web/components/assistant-ui/thread.tsxWhat to do
.includes()calls:.every()calls that check membership:Acceptance criteria
disabledToolsSetis auseMemo-wrappedSet.includes()/.every()calls ondisabledToolsare replaced with.has()on the Set