Description
In ZeroProvider.tsx, the opts object is recreated on every render and spread into ZeroReactProvider. If the provider compares props by reference internally, this can cause extra reconnects or internal churn on every parent re-render.
File to change
surfsense_web/components/providers/ZeroProvider.tsx (lines 51-61)
Current code
const opts = {
userID,
schema,
queries,
context,
cacheURL,
auth,
};
return (
<ZeroReactProvider {...opts}>
What to do
const opts = useMemo(
() => ({ userID, schema, queries, context, cacheURL, auth }),
[userID, schema, queries, context, cacheURL, auth]
);
return (
<ZeroReactProvider {...opts}>
Also verify that context and auth values are stable references (not recreated every render). If they are, memoize those too:
const context = useMemo(
() => (hasUser ? { userId: String(user.id) } : undefined),
[hasUser, user?.id]
);
Acceptance criteria
opts is memoized with useMemo
context and auth are stable references
- Zero sync still works correctly
Description
In
ZeroProvider.tsx, theoptsobject is recreated on every render and spread intoZeroReactProvider. If the provider compares props by reference internally, this can cause extra reconnects or internal churn on every parent re-render.File to change
surfsense_web/components/providers/ZeroProvider.tsx(lines 51-61)Current code
What to do
Also verify that
contextandauthvalues are stable references (not recreated every render). If they are, memoize those too:Acceptance criteria
optsis memoized withuseMemocontextandauthare stable references