RocketChat / RocketChat/EmbeddedChat

Permissions change-detection in useFetchChatData is dead — applyPermissions re-runs on every call

Open Beginner friendly
#1,317 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
165
Forks
381
Avg merge
1d 2h
Merged PRs (30d)
1

Description

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,
};

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/react/src/hooks/useFetchChatData.js and inspect fetchAndSetPermissions, especially the comparison with permissionsRef.current.raw. Confirm the stored permission data supports the intended unchanged-permissions check. Done means repeated calls with unchanged permissions no longer rebuild the map or reapply permissions.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
85/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.