Skip to content

fix(react): cache raw permissions in useFetchChatData - #1389

Open
ydvvdinesh wants to merge 1 commit into
RocketChat:developfrom
ydvvdinesh:fix/react-permissions-cache
Open

ydvvdinesh wants to merge 1 commit into
RocketChat:developfrom
ydvvdinesh:fix/react-permissions-cache

Conversation

@ydvvdinesh

@ydvvdinesh ydvvdinesh commented Oct 16, 2026 •

Copy link
Copy Markdown

fix(react): cache raw permissions in useFetchChatData

Acceptance Criteria fulfillment

  • Cache raw: permissions in permissionsRef.current inside useFetchChatData.js so isEqual(permissionsRef.current.raw, permissions) prevents redundant state updates and re-renders.
  • Configure packages/react/babel.config.js to enable module transformation during test runs.
  • Add unit test suite in packages/react/src/hooks/useFetchChatDataPermissions.test.js verifying cache hits prevent duplicate store dispatches.

Description

In useFetchChatData.js, fetchAndSetPermissions performs 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.

- 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>
@CLAassistant

CLAassistant commented Oct 16, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants