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

Pagination resets after filtering #3703

Closed
Evgeny81 opened this issue Sep 17, 2019 · 7 comments
Closed

Pagination resets after filtering #3703

Evgeny81 opened this issue Sep 17, 2019 · 7 comments
Assignees
Labels

Comments

@Evgeny81
Copy link
Contributor

Evgeny81 commented Sep 17, 2019

What you were expecting:
After new value added to some filter field, pagination per page value doesn't reset to default.

What happened instead:
When I choose not default value of per page and change some filter value, per page value resets to default value of 10.

Steps to reproduce:

  1. Choose 5 or 25 rows per page in the pagination area
  2. Type some value to any filter field
  3. Rows per page resets to 10

Related code:
https://codesandbox.io/s/mystifying-silence-dvjev

Environment

React-admin version: 3.0.0-alpha.4
React version: 16.9.0
Browser: Chrome

@djhi
Copy link
Collaborator

djhi commented Sep 17, 2019

Thanks for reporting. Reproduced

@fxzhukov
Copy link
Contributor

fxzhukov commented Sep 19, 2019

@Kmaschta, @fzaninotto, @djhi PR created - take a look, please. Also, please feel free to propose any better solution.

@fzaninotto
Copy link
Member

Fixed by #3716

@m4theushw
Copy link
Contributor

This bug is back. I think that it is related to FormSpy calling an old setFilters. See final-form/react-final-form#569

pagination

@fzaninotto
Copy link
Member

Confirmed. I'm reopening the bug.

@fzaninotto fzaninotto reopened this Oct 28, 2019
@fzaninotto fzaninotto added the v3 label Oct 28, 2019
@fzaninotto
Copy link
Member

I've found the bug. It's in FilterForm:

        <Form
            onSubmit={handleFinalFormSubmit}
            initialValues={mergedInitialValuesWithDefaultValues}
            render={formProps => (
                <>
                    <FormSpy
                        subscription={FormSpySubscription}
                        onChange={({ pristine, values }) => {
                            if (pristine) {
                                return;
                            }
                            props && props.setFilters(values);
                        }}
                    />
                    <FilterForm classes={classes} {...formProps} {...rest} />
                </>
            )}
        />

When a user adds a filter, the FormSpy triggers the initial onChange, ignoring any change in setFilters - and therefore ignoring any change to the list state. It's due to a bug in react-final-form (final-form/react-final-form#569) fixed (in final-form/react-final-form#572) but not yet released.

Unfortunately, unless we rewrite final-form's useFormState ourselves, it's impossible to solve in react-admin. So we'll have to wait for a new release.

@fzaninotto
Copy link
Member

Fixed by #4000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants