Repository navigation
fix(react): memoize fetched permissions and prevent redundant store u… - #1445
Open
swarnendusahu10-dotcom wants to merge 2 commits into
Open
swarnendusahu10-dotcom wants to merge 2 commits into
swarnendusahu10-dotcom wants to merge 2 commits into
Conversation
swarnendusahu10-dotcom
force-pushed
the
fix/issue-1317-permissions-memoization-leak
branch
from
November 27, 2026 10:45
99d5277 to
fb64966
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
Closes #1317.
In
packages/react/src/hooks/useFetchChatData.js, the permissions change-detection check infetchAndSetPermissions:intended to memoize permissions and avoid redundant store updates. However,
permissionsRef.current.rawwas never assigned when settingpermissionsRef.current(only{ map: permissionsMap }was assigned).The Problem
permissionsRef.current.rawremainedundefinedacross all cycles.JSON.stringify(permissions) !== JSON.stringify(undefined)evaluated totrueon every single invocation,applyPermissions()fired continuously, executing 6 separate Zustand store updates (setViewUserInfoPermissions,setDeleteMessageRoles,setDeleteOwnMessageRoles,setForceDeleteMessageRoles,setUserPinPermissions,setEditMessagePermissions) and triggering unnecessary re-renders across the component tree.createPermissionsMaplacked an array guard onpermissions.update, causing an unhandledTypeError: Cannot read properties of undefined (reading 'map')if the API returned an error or incomplete payload.Fix
raw: permissionsinsidepermissionsRef.currentso memoization functions as originally intended.Array.isArray(permissions?.update)) in bothcreatePermissionsMapandfetchAndSetPermissionsto guard against network glitches or non-200 responses.Testing & Verification
prettier@2.8.1matching.prettierrc(All matched files use Prettier code style!).yarn workspace @embeddedchat/react build).