Permissions change-detection in useFetchChatData is dead — applyPermissions re-runs on every call
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 85/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- javascript, react
- Domain
- frontend
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.
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,
};
- Dominant language
- JavaScript
- Stars
- 165
- Forks
- 381
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from RocketChat/EmbeddedChat
-
enhancement
Difficulty 1/5 Under an hour Newbie friendliness 84/100
RocketChat/EmbeddedChat#1360 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
RocketChat/EmbeddedChat#1315 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
RocketChat/EmbeddedChat#1313 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
RocketChat/EmbeddedChat#1294 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
RocketChat/EmbeddedChat#1287 · 2 comments ·
All issues in RocketChat/EmbeddedChat
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·