fix: store raw permissions so change-detection in useFetchChatData works#1318
Open
yash113gadia wants to merge 1 commit into
Open
fix: store raw permissions so change-detection in useFetchChatData works#1318yash113gadia wants to merge 1 commit into
yash113gadia wants to merge 1 commit into
Conversation
…very call
fetchAndSetPermissions guards its work with
`JSON.stringify(permissions) !== JSON.stringify(permissionsRef.current.raw)`,
but the ref was only ever assigned `{ map: permissionsMap }` — `.raw` was
never written. So the comparison read `undefined` every time and was always
truthy, meaning the permission map was rebuilt and applyPermissions (which
fires six zustand setters) ran on every call, even when permissions were
unchanged. The change-detection was effectively dead.
Store the raw permissions alongside the map so the guard works as intended:
unchanged permissions now short-circuit and return the cached map.
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.
Closes #1317
Problem
fetchAndSetPermissionsguards re-applying permissions with:…but the ref was only ever set to
{ map: permissionsMap }—.rawis never written. So the comparison readsundefinedevery time and is always truthy, meaning the permission map is rebuilt andapplyPermissions(six zustand setters) runs on every call, even when permissions haven't changed. The change-detection is dead code.Fix
Store the raw permissions next to the map so the guard can actually compare:
Now an unchanged permissions payload short-circuits and returns the cached map, avoiding redundant setter calls / re-renders. One-line, behavior-preserving for the changed-permissions path.