Description
fetchAndSetPermissions in packages/react/src/hooks/useFetchChatData.js is meant to skip re-applying permissions when they haven't changed. It guards the work with:
if (
!permissionsRef.current ||
JSON.stringify(permissions) !== JSON.stringify(permissionsRef.current.raw)
) {
const permissionsMap = createPermissionsMap(permissions);
permissionsRef.current = {
map: permissionsMap, // <-- `.raw` is never stored
};
applyPermissions(permissionsMap);
}
return permissionsRef.current.map;
But permissionsRef.current is only ever assigned { map: permissionsMap } — the .raw property the comparison reads is never written anywhere (grep confirms line 105 is the only reference to .raw).
Effect
permissionsRef.current.raw is always undefined, so JSON.stringify(permissions) !== JSON.stringify(undefined) is always true. The guard never short-circuits, so on every call the permission map is rebuilt and applyPermissions runs — firing all six zustand setters (setViewUserInfoPermissions, setDeleteMessageRoles, setDeleteOwnMessageRoles, setForceDeleteMessageRoles, setUserPinPermissions, setEditMessagePermissions) — even when permissions are unchanged. The intended change-detection / caching is effectively dead, causing redundant state updates and re-renders.
Fix
Store the raw permissions alongside the map so the comparison has something to compare against:
permissionsRef.current = {
raw: permissions,
map: permissionsMap,
};
Description
fetchAndSetPermissionsinpackages/react/src/hooks/useFetchChatData.jsis meant to skip re-applying permissions when they haven't changed. It guards the work with:But
permissionsRef.currentis only ever assigned{ map: permissionsMap }— the.rawproperty the comparison reads is never written anywhere (grepconfirms line 105 is the only reference to.raw).Effect
permissionsRef.current.rawis alwaysundefined, soJSON.stringify(permissions) !== JSON.stringify(undefined)is always true. The guard never short-circuits, so on every call the permission map is rebuilt andapplyPermissionsruns — firing all six zustand setters (setViewUserInfoPermissions,setDeleteMessageRoles,setDeleteOwnMessageRoles,setForceDeleteMessageRoles,setUserPinPermissions,setEditMessagePermissions) — even when permissions are unchanged. The intended change-detection / caching is effectively dead, causing redundant state updates and re-renders.Fix
Store the raw permissions alongside the map so the comparison has something to compare against: