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(core): wrap setFiltersFn with useCallback #6386

Merged
merged 3 commits into from
Oct 14, 2024

Conversation

hugorezende
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

Adding the setFilters as a dependency in the useEffect hook causes infinite loop since setFiltersFn are not wrapped in useCallbacks

What is the new behavior?

No infinite loop

fixes #6385

@hugorezende hugorezende requested a review from a team as a code owner October 3, 2024 20:02
Copy link

changeset-bot bot commented Oct 3, 2024

🦋 Changeset detected

Latest commit: 990f8e9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@refinedev/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@BatuhanW BatuhanW changed the base branch from master to releases/october October 7, 2024 12:23
@BatuhanW BatuhanW requested a review from aliemir October 8, 2024 14:51
Copy link
Member

@aliemir aliemir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @hugorezende thank you for the PR! I've made a small change request in the changeset and left two comments for the dependency arrays, can you check them and apply the necessary changes? 🙏

Then, we can include this in our next release 🚀 🚀

unionFilters(preferredPermanentFilters, newFilters, prevFilters),
);
},
[setFilters, unionFilters, preferredPermanentFilters],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setFilters is a SetStateAction and unionFilters is an imported util, they don't need to be included in the dependency arrays.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also can you make a similar update in the setSortWithUnion function as well? 🙏

Copy link
Contributor Author

@hugorezende hugorezende Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @aliemir, thanks for checking the PR. I'm just so used with the exhaustive-deps rule i didn't realised it 😄
Just fixed those and also added it on setSortWithUnion
990f8e9

"@refinedev/core": patch
---

fix: fix setFiltersFn #6385
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fix: fix setFiltersFn #6385
fix(core): wrap `setFilters` and `setSorters` methods with `useCallback` to prevent looping re-renders

Having a bit more info in the first line will be great for the changelogs 😅

@hugorezende hugorezende requested a review from aliemir October 11, 2024 14:24
@BatuhanW BatuhanW added this to the October Release milestone Oct 14, 2024
Copy link
Member

@aliemir aliemir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@aliemir aliemir merged commit bfe28f0 into refinedev:releases/october Oct 14, 2024
12 checks passed
This was referenced Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] setFilters from useDataGrid causes infinite loop inside useEffects
4 participants