-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overly aggressive shouldComponentUpdate for the List component #1488
Comments
What if you add a |
@fzaninotto Well that works, but don't think that's a nice way, yes? |
The alternative is to check about children, but in your example the change happens in the grandchildren. |
Hmm, in that case probably it makes sense to let the children decide whether to re-render? |
no, because in that case a lot of rerenders have already occurred (title, filters, pagination). |
What I mean is that things like title, filters, pagination, and datagrid can implement their own |
I believe that what you mention is related to my problem too, see below: Note: Eventually, adding a |
Is this issue still related to the newer versions of react admin? |
Fixed by #3635 |
What you were expecting:
When the body of a ResourceList (e.g., PostList, etc) changes (e.g., due to state change), the changes should be picked up by List and Datagrid, and trigger a UI update.
What happened instead:
The changes in ResourceList are not being picked up by List and Datagrid.
Steps to reproduce:
Referring to the sample code below. Run
window.setShowId(false)
. The ID column should disappear, but it doesn't. Looking at the React Developer Tools, I can confirm that the state is indeed updated.Related code:
Other information:
This issue is very much inspired by the need to show/hide columns on the resource list page. This has been raised at least twice (#1381, #1386) here and at least once on Stack Overflow (https://stackoverflow.com/q/48211984/211319). @djhi proposed a solution, but it did not work.
I have done some digging and found the bug and a fix. Essentially, List has a pretty aggressive
shouldComponentUpdate
. Since it does not check if the children have changed, it returns false and no rendering is done. A simple fix here is to always return true inshouldComponentUpdate
. (I have tested this and the problem went away.) However, obviously this is not the right way. In fact, I am not sure what is the right way to solve this. I'd be happy to send in a PR to fix this if the core team can give some pointers on this issue.Notice that this issue can manifest in other forms. For e.g., if one were to customize the properties of the underlying table component using
<Datagrid options={ someStateDerivedValue } />
, this, too, will fail because of the same issue.Environment
The text was updated successfully, but these errors were encountered: