react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

First click on next button does nothing

Open OoDeLally opened this issue 6 years ago • 12 comments

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-simple dataProvider, so I doubt it comes from the dataProvider.

  • The first time I click next, the app makes 4 quick requests (with ra-data-graphql-simple):

    1. allUsers with arguments { page: 1, perPage: 5, sortField: 'id', sortOrder: 'ASC', filter: {} }
    2. _allUsersMeta with arguments { page: 1, perPage: 5, filter: {} }
    3. allUsers with arguments { page: 0, perPage: 5, sortField: 'id', sortOrder: 'ASC', filter: {} }
    4. _allUsersMeta with 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

OoDeLally avatar Apr 01 '20 10:04 OoDeLally

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

fzaninotto avatar Apr 01 '20 14:04 fzaninotto

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>.

fzaninotto avatar Apr 01 '20 16:04 fzaninotto

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)

OoDeLally avatar Apr 01 '20 18:04 OoDeLally

The problem is resolved after build. pagination works in production. 15074#issuecomment-471197572

Taxellool avatar Apr 05 '20 15:04 Taxellool

Hey, I've got a similar problem that is not resolved in the production build.

  • When clicking next page in a view, it redirects to ".../#/resourceName?order=ASC&page=2&perPage=10&sort=id"
  • 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 avatar Apr 06 '20 07:04 ilaif

@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.

fzaninotto avatar Apr 06 '20 09:04 fzaninotto

Let me reopen this, as the core problem (StrictMode double rendering breaks pagination) is indeed a bug, and we need to investigate further.

fzaninotto avatar Apr 14 '20 10:04 fzaninotto

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.

michelem09 avatar Apr 19 '20 05:04 michelem09

Fixed by #4718

fzaninotto avatar May 04 '20 17:05 fzaninotto

I use lastest version of react-admin (3.1.7) but have the same problems, anyone has solution :)

techmodule avatar Jul 17 '21 02:07 techmodule

I'm also using the latest version of react-admin (3.19.10) and I'm having the same problem :(.

joaobispo2077 avatar Mar 17 '22 20:03 joaobispo2077

Please open a new issue by following the issue template.

fzaninotto avatar Mar 22 '22 09:03 fzaninotto