From be228ad8a715ae419903090abd8a72ef2de7a246 Mon Sep 17 00:00:00 2001 From: Yash Gadia Date: Tue, 2 Jun 2026 12:13:09 +0530 Subject: [PATCH] fix: cache permissions correctly so applyPermissions doesn't re-run every call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fetchAndSetPermissions guards its work with `JSON.stringify(permissions) !== JSON.stringify(permissionsRef.current.raw)`, but the ref was only ever assigned `{ map: permissionsMap }` — `.raw` was never written. So the comparison read `undefined` every time and was always truthy, meaning the permission map was rebuilt and applyPermissions (which fires six zustand setters) ran on every call, even when permissions were unchanged. The change-detection was effectively dead. Store the raw permissions alongside the map so the guard works as intended: unchanged permissions now short-circuit and return the cached map. --- packages/react/src/hooks/useFetchChatData.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/react/src/hooks/useFetchChatData.js b/packages/react/src/hooks/useFetchChatData.js index e37e3dc65..0af73dc4c 100644 --- a/packages/react/src/hooks/useFetchChatData.js +++ b/packages/react/src/hooks/useFetchChatData.js @@ -107,6 +107,7 @@ const useFetchChatData = (showRoles) => { const permissionsMap = createPermissionsMap(permissions); permissionsRef.current = { + raw: permissions, map: permissionsMap, };