Skip to content

fix(table-core): filterFn_between/betweenInclusive autoRemove never removes array filter values#6332

Merged
KevinVandy merged 1 commit into
TanStack:betafrom
JSap0914:fix/between-autoremove-array-falsy
Jun 17, 2026
Merged

fix(table-core): filterFn_between/betweenInclusive autoRemove never removes array filter values#6332
KevinVandy merged 1 commit into
TanStack:betafrom
JSap0914:fix/between-autoremove-array-falsy

Conversation

@JSap0914

@JSap0914 JSap0914 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Bug

filterFn_between and filterFn_betweenInclusive have:

autoRemove: (val: any) => !val

Because the filter value for these functions is always a [min, max] tuple (an array), and arrays are always truthy in JavaScript, !val is always false. This means the filter is never auto-removed — even when both endpoints are cleared to undefined, null, or ''.

Effect: A user who empties both range inputs ends up with an active filter that passes all rows but is never cleaned up from column filter state.

Fix

Align the autoRemove predicate with the pattern already used by filterFn_inNumberRange:

// Before (never removes an array input)
autoRemove: (val: any) => !val

// After (removes when both endpoints are falsy; preserves 0 as valid)
autoRemove: (val: any) => testFalsy(val) || (testFalsy(val[0]) && testFalsy(val[1]))

testFalsy checks undefined | null | '', so 0 is correctly preserved as a valid endpoint.

Verification

pnpm vitest run packages/table-core/tests/unit/fns/filterFns.test.ts

Before fix: 6 new tests fail (autoRemove returns false for empty-endpoint arrays).
After fix: 63/63 tests pass (51 pre-existing + 12 new).

This fix was developed with AI assistance.

Summary by CodeRabbit

  • Bug Fixes

    • Improved range filter behavior to correctly remove filters when both endpoints are empty, rather than only when the entire filter value is empty. This provides better handling of incomplete range selections.
  • Tests

    • Added comprehensive test coverage for range filter removal logic to ensure correct behavior across various endpoint scenarios.

…er removing array filter values

filterFn_between and filterFn_betweenInclusive had `autoRemove: (val: any) => !val`.
Since any array is truthy in JavaScript, `!val` is always `false` for the
`[min, max]` tuple these filters receive, meaning the filter is NEVER
auto-removed — even when both endpoints are empty strings, null, or undefined.

A user who clears both range inputs ends up with an active filter that passes
all rows but can never be auto-removed from column filter state.

Fix: align with the same pattern used by filterFn_inNumberRange:
  autoRemove: (val) => testFalsy(val) || (testFalsy(val[0]) && testFalsy(val[1]))

This correctly removes the filter when both endpoints are falsy (undefined, null,
or empty string) while preserving 0 as a valid endpoint value.

Fixes: filterFns.between and filterFns.betweenInclusive auto-remove logic
Copilot AI review requested due to automatic review settings June 17, 2026 12:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The autoRemove predicate for the between and betweenInclusive range filter functions is updated to use testFalsy and per-endpoint checks instead of a bare !val. Tests are added covering undefined, null, empty string, 0, and single-endpoint inputs.

Changes

Range Filter autoRemove Fix

Layer / File(s) Summary
autoRemove logic and tests for between/betweenInclusive
packages/table-core/src/fns/filterFns.ts, packages/table-core/tests/unit/fns/filterFns.test.ts
Both range filter autoRemove functions replace !val with testFalsy(val) || (testFalsy(val[0]) && testFalsy(val[1])). Tests assert autoRemove returns true for all-empty endpoints and false for valid numeric inputs including 0 and single-endpoint cases.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐇 Hop, hop, the filter's reborn,
No longer fooled by zero's form!
Both endpoints checked, not just the pair,
testFalsy leaps with utmost care.
The range is clean, the table bright —
This bunny's autoRemove is right! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: fixing a bug where autoRemove never removes array filter values for between/betweenInclusive functions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/table-core/src/fns/filterFns.ts (1)

213-223: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Align blank-endpoint checks with the new autoRemove semantics.

autoRemove now treats null as empty, but the row predicates still only treat ''/undefined as open-ended. That makes [null, 10] and [5, null] behave as bounded ranges due to Number(null) === 0, which is inconsistent and can filter rows incorrectly.

Suggested fix
 const filterFn_between = Object.assign(
@@
-    ((['', undefined] as Array<any>).includes(filterValues[0]) ||
+    (testFalsy(filterValues[0]) ||
       filterFn_greaterThan(row, columnId, filterValues[0])) &&
@@
-      (['', undefined] as Array<any>).includes(filterValues[1]) ||
+      testFalsy(filterValues[1]) ||
       filterFn_lessThan(row, columnId, filterValues[1])),
@@
 const filterFn_betweenInclusive = Object.assign(
@@
-    ((['', undefined] as Array<any>).includes(filterValues[0]) ||
+    (testFalsy(filterValues[0]) ||
       filterFn_greaterThanOrEqualTo(row, columnId, filterValues[0])) &&
@@
-      (['', undefined] as Array<any>).includes(filterValues[1]) ||
+      testFalsy(filterValues[1]) ||
       filterFn_lessThanOrEqualTo(row, columnId, filterValues[1])),

Also applies to: 237-247

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/table-core/src/fns/filterFns.ts` around lines 213 - 223, The
blank-endpoint checks in the row predicates are not aligned with the autoRemove
semantics. Currently, the checks only treat empty strings and undefined as
open-ended endpoints by using (['', undefined] as Array<any>).includes(), but
autoRemove treats null as empty too via testFalsy(). This inconsistency causes
null values to be converted to Number(null) === 0, resulting in incorrect
filtering behavior. Update the blank-endpoint checks in both the
filterFn_greaterThan condition (for filterValues[0]) and the filterFn_lessThan
condition (for filterValues[1]) to include null alongside '' and undefined in
the array check. Also apply the same fix to the similar pattern mentioned at
lines 237-247.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/table-core/src/fns/filterFns.ts`:
- Around line 213-223: The blank-endpoint checks in the row predicates are not
aligned with the autoRemove semantics. Currently, the checks only treat empty
strings and undefined as open-ended endpoints by using (['', undefined] as
Array<any>).includes(), but autoRemove treats null as empty too via testFalsy().
This inconsistency causes null values to be converted to Number(null) === 0,
resulting in incorrect filtering behavior. Update the blank-endpoint checks in
both the filterFn_greaterThan condition (for filterValues[0]) and the
filterFn_lessThan condition (for filterValues[1]) to include null alongside ''
and undefined in the array check. Also apply the same fix to the similar pattern
mentioned at lines 237-247.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d461f38c-ce47-42c9-b637-9568ee86da11

📥 Commits

Reviewing files that changed from the base of the PR and between 26fc105 and b4949ea.

📒 Files selected for processing (2)
  • packages/table-core/src/fns/filterFns.ts
  • packages/table-core/tests/unit/fns/filterFns.test.ts

@nx-cloud

nx-cloud Bot commented Jun 17, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit b4949ea

Command Status Duration Result
nx affected --targets=test:eslint,test:sherif,t... ✅ Succeeded 3m 16s View ↗
nx run-many --targets=build --exclude=examples/** ✅ Succeeded 26s View ↗

☁️ Nx Cloud last updated this comment at 2026-06-17 16:07:16 UTC

@pkg-pr-new

pkg-pr-new Bot commented Jun 17, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/angular-table@6332

@tanstack/angular-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/angular-table-devtools@6332

@tanstack/lit-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/lit-table@6332

@tanstack/match-sorter-utils

npm i https://pkg.pr.new/TanStack/table/@tanstack/match-sorter-utils@6332

@tanstack/preact-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/preact-table@6332

@tanstack/preact-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/preact-table-devtools@6332

@tanstack/react-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/react-table@6332

@tanstack/react-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/react-table-devtools@6332

@tanstack/solid-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/solid-table@6332

@tanstack/solid-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/solid-table-devtools@6332

@tanstack/svelte-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/svelte-table@6332

@tanstack/table-core

npm i https://pkg.pr.new/TanStack/table/@tanstack/table-core@6332

@tanstack/table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/table-devtools@6332

@tanstack/vue-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/vue-table@6332

@tanstack/vue-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/vue-table-devtools@6332

commit: b4949ea

@KevinVandy KevinVandy merged commit 516ab67 into TanStack:beta Jun 17, 2026
8 checks passed
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.

3 participants