Skip to content

feat(mui): Add configurable filter debouncing to useDataGrid hook#7396

Open
Alex-Murmu wants to merge 4 commits intorefinedev:mainfrom
Alex-Murmu:fix/datagrid-filter-debounce
Open

feat(mui): Add configurable filter debouncing to useDataGrid hook#7396
Alex-Murmu wants to merge 4 commits intorefinedev:mainfrom
Alex-Murmu:fix/datagrid-filter-debounce

Conversation

@Alex-Murmu
Copy link
Copy Markdown

@Alex-Murmu Alex-Murmu commented Apr 14, 2026

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

The useDataGrid hook sends API requests on every filter change, including every keystroke in text filters. This causes:

  • API flooding with unnecessary requests
  • Race conditions when responses arrive out of order
  • Lost characters when typing quickly
  • Poor UX on slow connections

Related to issue #7369

What is the new behavior?

Added configurable, smart filter debouncing:

  1. New filterDebounceMs option (default: 500ms) - Controls debounce delay
  2. New filterDebounceMode option - Three modes:
    • 'smart' (default): Only debounce text filters (contains, startswith), apply categorical filters (eq, in) immediately
    • 'all': Debounce all filter changes
    • 'off': No debouncing
  3. New callbacks: onFilterDebounceStart and onFilterDebounceEnd for loading states
  4. New isPendingFilters state: Track when filters are being debounced

Example Usage

const { dataGridProps, isPendingFilters } = useDataGrid({
  resource: 'users',
  filterDebounceMs: 500,
  filterDebounceMode: 'smart',
});

return (
  <>
    {isPendingFilters && <CircularProgress />}
    <DataGrid {...dataGridProps} />
  </>
);

Copilot AI review requested due to automatic review settings April 14, 2026 15:55
@Alex-Murmu Alex-Murmu requested a review from a team as a code owner April 14, 2026 15:55
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 14, 2026

🦋 Changeset detected

Latest commit: 0c927f5

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

This PR includes changesets to release 1 package
Name Type
@refinedev/mui Minor

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

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds configurable, mode-based debouncing for server-side filter updates in the @refinedev/mui useDataGrid hook to reduce request flooding and improve typing UX (issue #7369).

Changes:

  • Introduces filterDebounceMs, filterDebounceMode (smart/all/off), debounce lifecycle callbacks, and isPendingFilters state to useDataGrid.
  • Updates server-side onFilterModelChange handling to debounce filter application based on mode.
  • Also bumps monorepo tooling deps (lerna, nx, vitest) and relaxes typing in Appwrite sorting utility.

Reviewed changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated 9 comments.

File Description
packages/mui/src/hooks/useDataGrid/index.ts Adds new hook options/state and implements debounced server-side filter application logic.
packages/appwrite/src/utils/getAppwriteSorting.ts Changes sorter iteration typing (introduces any) in Appwrite query sorting helper.
package.json Upgrades dev tooling dependencies (lerna/nx/vitest).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/mui/src/hooks/useDataGrid/index.ts
Comment thread package.json Outdated
Comment thread packages/mui/src/hooks/useDataGrid/index.ts Outdated
Comment thread packages/mui/src/hooks/useDataGrid/index.ts
Comment thread packages/appwrite/src/utils/getAppwriteSorting.ts
Comment thread packages/mui/src/hooks/useDataGrid/index.ts Outdated
Comment thread packages/mui/src/hooks/useDataGrid/index.ts Outdated
Comment thread packages/mui/src/hooks/useDataGrid/index.ts Outdated
Comment thread packages/mui/src/hooks/useDataGrid/index.ts Outdated
@Alex-Murmu Alex-Murmu closed this Apr 14, 2026
@Alex-Murmu Alex-Murmu reopened this Apr 14, 2026
@Alex-Murmu Alex-Murmu closed this Apr 14, 2026
@Alex-Murmu Alex-Murmu reopened this Apr 14, 2026
@Alex-Murmu Alex-Murmu force-pushed the fix/datagrid-filter-debounce branch 2 times, most recently from ad9cf0f to 17e6c30 Compare April 14, 2026 17:59
@Alex-Murmu Alex-Murmu closed this Apr 14, 2026
@Alex-Murmu Alex-Murmu reopened this Apr 14, 2026
- Add filterDebounceMs option (default: 500ms)
- Add filterDebounceMode option ('smart', 'all', 'off')
- Add onFilterDebounceStart and onFilterDebounceEnd callbacks
- Add isPendingFilters state tracking
- Smart mode debounces only text filters
- Fixes refinedev#7369

fix: feat(mui): Add configurable filter debouncing to useDataGrid hook

- Remove unused useDebounce hook
- Fix smart mode to only debounce when text filters present
- Add eq/ne/ncontains to text operators list
- Fix isPendingFilters state consistency
- Add comprehensive tests for debouncing behavior
- Add changeset for version bump
@Alex-Murmu Alex-Murmu force-pushed the fix/datagrid-filter-debounce branch from 17e6c30 to 4019794 Compare April 14, 2026 18:17
@Alex-Murmu Alex-Murmu closed this Apr 14, 2026
@Alex-Murmu Alex-Murmu reopened this Apr 14, 2026
- Revert vitest from ^4.1.4 to ^2.1.8 (unrelated to filter debouncing feature)
- Revert lerna from ^9.0.7 to ^6.2.0 (unrelated to this PR)
- Revert nx from ^22.6.5 to ^18.0.0 (unrelated to this PR)
- Fix Appwrite sorting typing from 'any' to proper CrudSorting type
…n text edits

In smart mode, only apply categorical filters when they actually change,
not on every keystroke. This prevents defeating the debouncing mechanism
when both text and categorical filters are active.

- Add previousCategoricalFiltersRef to track categorical filter state
- Only apply categorical filters if they changed (deep equality check)
- Fixes: categorical filters re-triggering API calls on every keystroke
  when text filters are being debounced
Copy link
Copy Markdown
Author

@Alex-Murmu Alex-Murmu left a comment

Choose a reason for hiding this comment

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

Q

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.

useDataGrid sends API requests on every keystroke causing performance issues and race conditions

2 participants