First click on next button does nothing
What you were expecting:
From a freshly loaded page, when clicking on the Next button, I should go to the next page.
What happened instead:
The page flickers, but nothing happens.
If then I click a second time on the next button, it finally takes me to the next page.
Steps to reproduce:
I've made a repo, with the basic starting tutorial
https://github.com/OoDeLally/react-admin-pagination-bug
(There are only 10 docs, so choose 5 rows / page so that a 2nd page is available.
Other information:
-
The bug also happens with the
ra-data-graphql-simpledataProvider, so I doubt it comes from the dataProvider. -
The first time I click
next, the app makes 4 quick requests (withra-data-graphql-simple):allUserswith arguments{ page: 1, perPage: 5, sortField: 'id', sortOrder: 'ASC', filter: {} }_allUsersMetawith arguments{ page: 1, perPage: 5, filter: {} }allUserswith arguments{ page: 0, perPage: 5, sortField: 'id', sortOrder: 'ASC', filter: {} }_allUsersMetawith arguments{ page: 0, perPage: 5, filter: {} }
So it seems like the first two are the "good" ones, but immediately after, there are the second two which rewind to the original page.
Environment
- React-admin version: 3.3.3 (bug also occurs in 3.0.0.).
- React version: 16.13.1
- Browser: Chrome
Reproduced. This is a serious regression, thanks for reporting it.
I pbuilt a CodeSandbox based on your repository: https://codesandbox.io/s/github/OoDeLally/react-admin-pagination-bug
OK, this is not a regression. I managed to isolate the difference with the simple example that triggers the problem. The culprit is <React.StrictMode>.
The problem disappears in my project as well once React.StrictMode is removed.
Could it be this? https://github.com/facebook/react/issues/15074 https://github.com/facebook/react/issues/18426 (it REALLY looks like this)
The problem is resolved after build. pagination works in production. 15074#issuecomment-471197572
Hey, I've got a similar problem that is not resolved in the production build.
- When clicking next page in a
- A fraction of time after it loads, it redirects again to page 1 and the URL changes to ".../#/agents?order=ASC&page=2&perPage=10&sort=id"
Looking at Redux timeline, I see:
{
type: '@@router/LOCATION_CHANGE',
payload: {
location: {
pathname: '/agents',
search: '?order=ASC&page=2&perPage=10&sort=id',
hash: ''
},
action: 'POP',
isFirstRendering: false
}
}
Just after the click on page.
Then, right before the unneeded redirect, I see:
{
type: '@@router/LOCATION_CHANGE',
payload: {
location: {
search: '?order=ASC&page=1&perPage=10&sort=id',
pathname: '/agents',
hash: ''
},
action: 'PUSH',
isFirstRendering: false
}
}
I suspect this bug happened after I upgraded from RA 2 to 3.
Current setup:
- react-admin:
3.4.0 - react:
16.13.1
Can this somehow be related? Or do you know what might be causing this? I don't use StrictMode anywhere in my code.
Thanks!
@ilaif This does not seem to be related. I suggest you ask your question on StackOverflow, as we don't do troubleshooting or support via the GitHub issues.
Let me reopen this, as the core problem (StrictMode double rendering breaks pagination) is indeed a bug, and we need to investigate further.
I can confirm this, with StrictMode my pagination resets to page 1 the first time I try to click next button or another page number. Pagination works correctly only when I hit all the pages at least one time. Removing StricMode everything works as it should.
Fixed by #4718
I use lastest version of react-admin (3.1.7) but have the same problems, anyone has solution :)
I'm also using the latest version of react-admin (3.19.10) and I'm having the same problem :(.
Please open a new issue by following the issue template.