-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Calling setSort and setFilters after one another filckers and doesn't setSort #4189
Comments
You call The flickr comes from the fact that we use the URL to store the sort and filters. In your case, your button should set the query parameter directly to do all in once. That would avoid the flickr. Anyway, this is not a bug IMO, so I'm closing the issue. |
No arguments passed to |
You're right - I believe that's an issue with a bad dependency in a |
Also having this issue in one of my projects; would love to know if anyone knows of a workaround or if a fix has been implemented. I'm on version 3.11.3. |
This was fixed by #6226, released in 3.15. |
@fzaninotto Thanks for your attention. Unfortunately, after migrating to 3.17.0, I'm still seeing the issue. I've replicated it in this sandbox: https://codesandbox.io/s/setsortsetfilter-je2em?file=/src/postList.jsx Basically, if I use either of the action buttons on the Posts list view to try to simultaneously set the sort and filters, the filters are set but the sort reverts back to what it was before the button was pressed. If you comment out either the setSort or SetFilters method in the button handlers, whatever method remains will work as expected. The two methods just won't work in tandem. Once again, thanks for your time! |
thanks for the sandbox, I managed to reproduce the issue. I'm reopening this ticket. |
The problem comes from the debounced version, because if I change your code to: const handleLeanne = () => {
const newFilters = { userId: 1 };
setFilters(newFilters, displayedFilters, false);
setSort("title", "ASC");
};
const handleErvin = () => {
const newFilters = { userId: 2 };
setFilters(newFilters, displayedFilters, false);
setSort("title", "DESC");
}; It works. We're using an internal debouncer to allow sync calls to setSort, setFilters, etc, and the lodash debouncer for setFilters alone. I think the two debouncers conflict with each other. Until we find a fix for this issue, I recommend that you use the direct (non debounced) call to setFilters by passing false as the third parameter. |
@fzaninotto Thank you for this suggestion! My form element that sets filters and sorts unmounts on load, so minimal risk to performance from un-debouncing setFilters. I've confirmed that in my application, your suggestion causes my functions to work with setSort and setFilters in tandem as expected. Again, thank you so much for your time and attention. |
As an update, I'd still love to see this bug fixed, as while defeating setFilters debounce allows setSort and setFilters to be called simultaneously, no debounce can result in errors such as incorrect dataprovider calls if a user changes list views while filters/sort are in the process of being set. I could probably whip together a codesandbox to display this if necessary. Thanks! |
+1 for this issue, I just ran into it as well. In our case, we have a set of tabs which swap out The debouncing fix doesn't seem to work for us --- it just results in the sort getting applied, but not the filter. |
In 4.0, we've found a workaround for this issue that I hope others will find helpful. After upgrading, I examined the Saved Query feature that has become available in version 4, and the way that loading a saved query uses react-router's useNavigate hook to change the URL instead of changing list context with setFilters, setSort, etc. The relevant code is found in the FilterButton component. I'm happy to report that calling navigate() with the list parameters will (so far) reliably change the filters and sort without debounce issues. Not sure if this closes the issue or not since presumably setSort and setFilters should still be able to be called simultaneously, but using useNavigate() essentially solves the implementation for my part. |
We should probably expose a |
Hi, Worse, the problem persists:
Here navigate() will do the same as setSort(), which is to go back to previous sorting. |
I can't replicate this problem in the e-commerce demo, where we have such a datagrid. I changed the TabbedDatagrid handleChange to: const handleChange = useCallback(
(event: React.ChangeEvent<{}>, value: any) => {
setFilters &&
setFilters(
{ ...filterValues, status: value },
displayedFilters,
false // no debounce, we want the filter to fire immediately
);
setSort({ field: 'date', order: 'DESC' });
},
[displayedFilters, filterValues, setFilters, setSort]
); And switching tabs properly changes both the filter and the sort. Please open a new issue with a reproduction. |
After carefully testing, I can confirm that disabling the debounce by passing false as the third parameter to I'm marking this as a documentation issue. |
What you were expecting:
I've built a button and added it as part of the
actions
props on aList
component. This button is intended to clear the filters applied to theList
as well as return the sort to its default value. The button calls thesetSort
andsetFilters
functions that are passed in as props toactions
. I expected the filters to be cleared and the sort to return to its default value.What happened instead:
Instead, what I'm seeing is that the filters are cleared (as expected) however the sort "flicks" to the default sort options and then flicks back to the previously selected sort.
If I call
setSort
alone orsetFilters
alone, they behave as expected and it seems that this issue only occurs when both are called after one another.Steps to reproduce:
https://codesandbox.io/s/elastic-raman-kvypc
Environment
The text was updated successfully, but these errors were encountered: