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

Fix FilterForm freezes the app when a deeply nested filter is reset #9337

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/ra-ui-materialui/src/list/filter/FilterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export const FilterForm = (props: FilterFormProps) => {
// Reapply filterValues when the URL changes or a user removes a filter
useEffect(() => {
const newValues = getFilterFormValues(getValues(), filterValues);
if (!isEqual(newValues, getValues())) {
const previousValues = getValues();
if (!isEqual(newValues, previousValues)) {
reset(newValues);
}
// The reference to the filterValues object is not updated when it changes,
Expand All @@ -66,7 +67,9 @@ export const FilterForm = (props: FilterFormProps) => {
// We can't rely on form state as it might not be synchronized yet
const isFormValid = await trigger();

if (isFormValid) {
// Check that the name is present to avoid setting filters when watch was
// triggered by a change on the ListContext values.
if (name && isFormValid) {
if (get(values, name) === '') {
const newValues = cloneDeep(values);
unset(newValues, name);
Expand Down Expand Up @@ -204,7 +207,11 @@ export const mergeInitialValuesWithDefaultValues = (
...initialValues,
});

const handleFormSubmit = () => {};
const handleFormSubmit = (event: React.FormEvent) => {
event.preventDefault();
event.stopPropagation();
return false;
};

const PREFIX = 'RaFilterForm';

Expand Down