Fix usePermissions always triggers a re-render even though the permissions are unchanged #5607
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.
Problem
All react-admin routes (list, edit, create, etc) are wrapped by
WithPermissions
. This component renders the page content optimistically with empty permissions, then callsauthProvider.getPermissions()
, and passes the result to the child.In many cases, this means the routes will render twice: once with empty permissions, and once with the permissions returned by the
authProvider
.Solution
WithPermissions
callsauthProvider.getPermissions()
with empty params. In many cases, the result of this call is always the same.useGetPermissions
can cache the result from the first call, and initialize its state with it.that way, in most cases, the return from
authProvider.getPermissions()
will be the same as the cached one, and we'll save a re-render.This should git a short perf boost to all apps, whether they use permissions or not.
Before
12 renders when coming back to the Post List page
After
11 renders when coming back to the Post List page