Skip to content

fix(core): preserve falsy values in getDefaultFilter#7451

Open
devteamaegis wants to merge 1 commit into
refinedev:mainfrom
devteamaegis:fix/get-default-filter-falsy-values
Open

fix(core): preserve falsy values in getDefaultFilter#7451
devteamaegis wants to merge 1 commit into
refinedev:mainfrom
devteamaegis:fix/get-default-filter-falsy-values

Conversation

@devteamaegis

Copy link
Copy Markdown

What's broken

getDefaultFilter returns filter.value || [], so a valid filter value of 0, false, or "" is silently replaced with []. It's used to seed form controls from active filters, so filtering on e.g. status = 0 or a boolean loses the real default and the control comes up empty.

getDefaultFilter("status", [{ field: "status", operator: "eq", value: 0 }])  // returns [] instead of 0

Why it happens

|| [] treats every falsy value as "missing". The [] fallback is only meant for an absent value (the existing empty-array test uses value: undefined).

Fix

Use nullish coalescing (?? []) so only undefined/null fall back to [].

Test

Added a case asserting 0, false, and "" round-trip through getDefaultFilter; the existing undefined → [] behaviour is unchanged.

getDefaultFilter used `filter.value || []`, replacing valid falsy
filter values (0, false, "") with an empty array. Default values for
numeric/boolean/empty-string filters were lost when populating form
controls. Use `filter.value ?? []` so only undefined/null fall back.
@changeset-bot

changeset-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 24ff9ac

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

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.

1 participant