fix(table-core): respect custom filterFn.autoRemove in shouldAutoRemoveFilter#6178
fix(table-core): respect custom filterFn.autoRemove in shouldAutoRemoveFilter#6178djk01281 wants to merge 3 commits intoTanStack:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 4c4dcf7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
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 |
📝 WalkthroughWalkthroughThe PR fixes shouldAutoRemoveFilter to respect a custom filterFn.autoRemove callback by invoking it first; adds a changeset for a patch release and new tests covering custom and default autoRemove behaviors across multiple filter values. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/table-core/tests/shouldAutoRemoveFilter.test.ts (2)
51-59: Consider addingnullcoverage to the "without filterFn" block for symmetry.The
noAutoRemovesuite already assertsnull → false. Adding the same assertion whenfilterFnisundefinedwould make the two "no autoRemove path" blocks consistent and complete.✅ Suggested addition
describe('without filterFn', () => { it('should remove undefined filter', () => { expect(shouldAutoRemoveFilter(undefined, undefined)).toBe(true) }) it('should remove empty string filter', () => { expect(shouldAutoRemoveFilter(undefined, '')).toBe(true) }) + + it('should keep null filter', () => { + expect(shouldAutoRemoveFilter(undefined, null)).toBe(false) + }) })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/table-core/tests/shouldAutoRemoveFilter.test.ts` around lines 51 - 59, Add a test case in the "without filterFn" describe block to cover null input: call shouldAutoRemoveFilter(undefined, null) and assert it returns true to mirror the existing noAutoRemove suite's null check; locate the test file tests/shouldAutoRemoveFilter.test.ts and update the describe('without filterFn') block that contains the existing undefined and '' expectations for shouldAutoRemoveFilter.
5-35: Add a test documenting the new capability: customautoRemovereturningfalseforundefined.The primary behavioral change introduced by this PR — beyond the empty-string fix — is that a custom
autoRemovereturningfalseforundefinednow prevents filter removal, whereas the old code would always remove forundefined. The current suite doesn't cover this case, so a regression would go undetected.✅ Suggested additional test fixture and case
+const neverAutoRemove: FilterFn<any> = (row, columnId, filterValue) => { + return filterValue === row.getValue(columnId) +} +neverAutoRemove.autoRemove = (_val) => false + describe('shouldAutoRemoveFilter', () => { describe('with custom autoRemove defined', () => { // ... existing tests ... + + it('should keep undefined filter when custom autoRemove returns false for it', () => { + expect(shouldAutoRemoveFilter(neverAutoRemove, undefined)).toBe(false) + }) })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/table-core/tests/shouldAutoRemoveFilter.test.ts` around lines 5 - 35, Add a test that verifies a custom filter's autoRemove returning false for undefined prevents removal: create a FilterFn (e.g., customNoRemoveUndefined) whose autoRemove = (v) => v !== undefined (or explicitly returns false when v === undefined) and add an it block using shouldAutoRemoveFilter(customNoRemoveUndefined, undefined) expecting false; place this alongside the other tests referencing customAutoRemove and shouldAutoRemoveFilter so the regression is covered.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/table-core/tests/shouldAutoRemoveFilter.test.ts`:
- Around line 51-59: Add a test case in the "without filterFn" describe block to
cover null input: call shouldAutoRemoveFilter(undefined, null) and assert it
returns true to mirror the existing noAutoRemove suite's null check; locate the
test file tests/shouldAutoRemoveFilter.test.ts and update the describe('without
filterFn') block that contains the existing undefined and '' expectations for
shouldAutoRemoveFilter.
- Around line 5-35: Add a test that verifies a custom filter's autoRemove
returning false for undefined prevents removal: create a FilterFn (e.g.,
customNoRemoveUndefined) whose autoRemove = (v) => v !== undefined (or
explicitly returns false when v === undefined) and add an it block using
shouldAutoRemoveFilter(customNoRemoveUndefined, undefined) expecting false;
place this alongside the other tests referencing customAutoRemove and
shouldAutoRemoveFilter so the regression is covered.
e079c29 to
4c4dcf7
Compare
🎯 Changes
Fixes #6101
Problem
In
shouldAutoRemoveFilter, the hardcoded(typeof value ==='string' && !value)check runs afterfilterFn.autoRemovevia||, so it can override a customautoRemovethat returnsfalsefor empty strings.This makes it impossible to use
''as a valid filter value with custom filter functions:Before
2026-02-22.4.52.43.mov
After
2026-02-22.5.27.43.mov
What changed
When
filterFn.autoRemoveis defined, only its result is used, without additional hardcoded checks overriding it.Built-in filter functions are unaffected since they all define
autoRemoveviatestFalsey.Notes
Same issue exists in v9 alpha branch:
packages/table-core/src/features/column-filtering/columnFilteringFeature.utils.ts✅ Checklist
pnpm test:pr.🚀 Release Impact
Summary by CodeRabbit
Bug Fixes
Tests