fix(filters): preserve non-default null filter state in useUrlState to fix the "All" filter - #417
fix(filters): preserve non-default null filter state in useUrlState to fix the "All" filter#417RaminGe wants to merge 3 commits into
Conversation
|
Thanks for tracking this down, the diagnosis is spot on ;) I applied it locally and the "All" button works. The One thing I'd like changed before merging. The diff also removes the
Nothing triggers this today (the map's distance Select has no Suggestion: keep export const parseNumber = {
parse: (v) => Number(v),
stringify: (v) => (v == null ? null : String(v)),
};
export const parseBoolean = {
parse: (v) => v === 'true',
stringify: (v) => (v == null ? null : String(v)),
};
// For state that is null | true | false. Null is a real value here, not an absence:
// `active` defaults to true, so absence already means true and null needs a spelling.
export const parseNullableBoolean = {
parse: (v) => (v === 'true' ? true : v === 'false' ? false : null),
stringify: (v) => (v === null ? 'all' : String(v)),
};That keeps your fix and puts the null handling where it belongs. Could you also add:
Happy to merge once those are in. Nice catch on this one. |
|
@orangecoding makes sense! Added and pushed |
Summary
Nice new filter update! I noticed the "All" activity button does not work (actually already before, just forgot to report it).
This PR fixes the issue where clicking the "All" activity filter (
active: null) failed to stay active and immediately reset toactive: trueon re-render.Root Cause
useUrlStateunconditionally deletednullvalues from search parameters. For filters likeactivewhosedefaultValueistrue, removing the key from the URL causeduseUrlStateto fall back totrue, preventingactive: nullfrom being retained.Fix
nullas"all"inparseNullableBoolean.stringify.nullparameter state inuseUrlState.setValuessoactive=allpersists in the URL.active=allURL serialization and reading.