[BUG] AiProxy ApiKeys: `useMemo` deps reference `onToggle` before its declaration – stale closures (TDZ error if not transpiled)
Description
columns is built with useMemo(..., [namespaceId, onToggle]) at line 275, but const onToggle is declared later at line 293. After Babel transpiles const to var, onToggle is undefined in the dependency array on every render, so columns is reused while namespaceId is unchanged and the handlers it captures (onToggle, fetchList) keep the first render's page, pageSize, queryKey and selectorId. If the build ever keeps native const, this is a ReferenceError (temporal dead zone) on every render.
Location
(The dependency/declaration order is still present in the current snapshot.)
src/routes/Plugin/AiProxy/ApiKeys/index.js:275(dependency array)src/routes/Plugin/AiProxy/ApiKeys/index.js:293(declaration ofonToggle)
Impact
Go to page 2 (or apply a filter) and flip an "Enabled" switch: the refetch uses page 1 with no filter while the pager still shows page 2, so the table and pager disagree.
Suggested fix
Declare fetchList and onToggle before evaluating the dependency array, using useCallback with all of their changing inputs if memoization is retained. Alternatively, drop useMemo and build the columns each render. Test a toggle after changing page/filter/selector as well as a namespace change.
Related existing
None
Verified source
Rechecked against Dashboard fed203e and, where applicable, ShenYu Admin 31e0c3e on 2026-09-26.
Hi! I'd like to work on this issue. My plan: declare fetchList and onToggle before the useMemo dependency array (wrapping them in useCallback with their changing inputs), so the columns no longer capture stale page/pageSize/queryKey/selectorId. I'll verify with a toggle-after-page/filter-change scenario.