Repository navigation
fix(react): cache raw permissions in useFetchChatData - #1389
Open
ydvvdinesh wants to merge 1 commit into
Open
ydvvdinesh wants to merge 1 commit into
ydvvdinesh wants to merge 1 commit into
Conversation
- Store raw permissions in permissionsRef.current so JSON.stringify comparison prevents redundant permission re-mapping and state setter calls when permissions are unchanged. - Configure packages/react/babel.config.js to allow ES module compilation during Jest test execution. - Add unit test verifying that identical permissions payloads do not trigger repeated state updates. Signed-off-by: Dinesh Yadav <bawwadinesh@gmail.com>
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.
fix(react): cache raw permissions in useFetchChatData
Acceptance Criteria fulfillment
raw: permissionsinpermissionsRef.currentinsideuseFetchChatData.jssoisEqual(permissionsRef.current.raw, permissions)prevents redundant state updates and re-renders.packages/react/babel.config.jsto enable module transformation during test runs.packages/react/src/hooks/useFetchChatDataPermissions.test.jsverifying cache hits prevent duplicate store dispatches.Description
In
useFetchChatData.js,fetchAndSetPermissionsperforms a check to skip processing if permissions haven't changed:if (
!permissionsRef.current ||
JSON.stringify(permissions) !== JSON.stringify(permissionsRef.current.raw)
)
However, permissionsRef.current was assigned { map: permissionsMap } without saving raw: permissions. Because permissionsRef.current.raw was always undefined, the comparison evaluated to true on every invocation, triggering redundant permission map calculations, store dispatches (setViewUserInfoPermissions), and component re-renders.
Storing raw: permissions in permissionsRef.current = { raw: permissions, map: permissionsMap } ensures identical permission responses are cleanly cached.
PR Test Details
Run node ../../node_modules/jest/bin/jest.js src/hooks/useFetchChatDataPermissions.test.js from packages/react
Verified that identical subsequent permissions payloads do not trigger repeated store setter calls.
Prettier and ESLint verified with 0 errors.