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

DataTable: in controlled pagination mode onPage always called initially with first=0 #3489

Closed
atzec opened this issue Oct 20, 2022 · 1 comment · Fixed by #3494
Closed

DataTable: in controlled pagination mode onPage always called initially with first=0 #3489

atzec opened this issue Oct 20, 2022 · 1 comment · Fixed by #3494
Assignees
Labels
React 18/19 Issue or pull request is *only* related to React 18/19 Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@atzec
Copy link

atzec commented Oct 20, 2022

Describe the bug

When trying to control pagination in DataTable (setting rows=, first= and onPage=) in React v18 development mode and under <React.StrictMode>, there is an initial onPage call without any user interaction. This call ignores the value of first= prop and signals first=0.

In effect, the page is always reset to the first one.

The behavior is not consistent with production build, where this doesn't happen. So, it is hard to implement a reliable workaround (such as: ignoring the first onPage call).

Probably related to React v18 changes to useEffect() in development mode.

Reproducer

https://codesandbox.io/s/primereact-test-forked-3kh0xq?file=/src/App.jsx

PrimeReact version

8.6.1

React version

18.x

Language

ALL

Build / Runtime

Create React App (CRA)

Browser(s)

No response

Steps to reproduce the behavior

  1. Simply open the page with the table.
  2. We expect to see the second page (the initial value in useState()).
  3. Instead, we see the first page.

Expected behavior

When I pass first={2}, I expect onPage not to be called without user interaction and if (for some reason) it must be called, it should be called with {first: 2} as an argument and not {first: 0}.

@atzec atzec added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Oct 20, 2022
@melloware melloware added React 18/19 Issue or pull request is *only* related to React 18/19 and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Oct 20, 2022
melloware added a commit to melloware/primereact that referenced this issue Oct 20, 2022
@melloware melloware added this to the 8.6.2 milestone Oct 20, 2022
@melloware melloware self-assigned this Oct 20, 2022
@melloware
Copy link
Member

Thanks for the reproducer!

@mertsincan mertsincan added the Type: Bug Issue contains a defect related to a specific component. label Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
React 18/19 Issue or pull request is *only* related to React 18/19 Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants