Skip to content
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

Missing total item count sends <List> to re-render loop #4094

Closed
kiirala opened this issue Dec 2, 2019 · 0 comments · Fixed by #4097
Closed

Missing total item count sends <List> to re-render loop #4094

kiirala opened this issue Dec 2, 2019 · 0 comments · Fixed by #4097
Assignees
Labels

Comments

@kiirala
Copy link

kiirala commented Dec 2, 2019

Originally reported on other issue, these likely share the same root cause: #4025 (comment)

What you were expecting:

Before react-admin 3.0, would render the available data regardless of the total item count.

What happened instead:

In react-admin 3.0, if total item count somehow ends up as NaN, the data is not shown. Instead, we get "Error: Too many re-renders."

Steps to reproduce:

I was using ra-data-simple-rest with a backend that provides content-range headers, but not total count of available items. For example: Content-Range: thingamajings 0-24/*

Next, ra-data-simple-rest fetches the total using total: parseInt(headers.get('content-range').split('/').pop(), 10). This results in total=NaN

Last important bit is in useQueryWithStore in ra-core: this checks for state updates using if (!isEqual(state.data, data) || state.total !== total) ... However, since total=NaN the second condition is never true. It thus always appears as if the fetched data has been updated, so this code attempts to update the related component. I don't have full details, how, but this results in scheduling updates over and over again, until the "Too many re-renders" check stops the loop.

Sample code

Example code here, based on the simple example: https://codesandbox.io/s/simple-t03vd
The only edits there are to dataProvider.js, to make it provide the problematic data.

Environment

  • React-admin version: 3.0.1
  • Last version that did not exhibit the issue (if applicable): 2.8.3
  • React version: 16.12.0
  • Browser: Chrome 78
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants