Repository navigation
Search Blocks: cap filter-checkbox list at Maximum items after session retention (SEARCH-208) - #48989
Conversation
…SEARCH-208) The ES request bounds the live aggregation at `size: maxItems`, but `checkboxFilterItems()` then folds in session-retained options (`retainedFilterOptions[filterKey]`) plus URL-seeded selections without a cap. As the visitor narrows their query each successive search appends new bucket values into the retained map, so the rendered list grows past the configured maximum — set Maximum items to 5, narrow the query, and you end up with 5 retained-at-count-0 entries plus the live buckets on top. Slice the sorted list to `Math.max( 1, config.maxItems ?? 10 )`. The sort already sinks unchecked count=0 items to the bottom so retained-but-now-empty entries drop first; selections beyond the cap still surface via the active-filters pill list. Mirrors `dateFilterItems()` which already slices its date-histogram buckets. Date filter unaffected — `mergeRetainedFilterOptions()` skips `filterType === 'date'` and `dateFilterItems` already caps in-loop.
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
This comment has been minimized.
This comment has been minimized.
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Search plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
This comment has been minimized.
This comment has been minimized.
Code Coverage SummaryCoverage changed in 1 file.
|
Review-cycle summary —
|
|
Claude finished @kangzj's task in 17s —— View job Review cycle completePR #48989 was merged at 2026-05-20T02:08:57Z as Summary:
|
Fixes SEARCH-208
Why
A Filter by Category / Tag / custom-taxonomy block has a "Maximum items" setting. Today, once a visitor narrows their search, the rendered checkbox list grows past that maximum — every search appends new categories to a session-retained map, and on the next render those retained entries stack on top of the live aggregation buckets. After the fix, the list is capped at the configured number, with live (non-zero count) entries preferred and retained-but-now-empty entries dropping off the bottom first.
Proposed changes
projects/packages/search/src/search-blocks/store/index.js— slice the merged item list incheckboxFilterItems()toMath.max( 1, config.maxItems ?? 10 )after the existing sort. The sort already sinks unchecked count=0 items to the bottom, so retained-but-now-empty entries drop first; selections beyond the cap still surface via the active-filters pill list.projects/packages/search/tests/js/search-blocks/filter-checkbox-view.test.jscovering the cap, the default-of-10 fallback, and the floor-at-1 coercion.Date filter unaffected —
mergeRetainedFilterOptions()already skipsfilterType === 'date'anddateFilterItems()slices in-loop.Screenshots
Captured against the local docker env (
https://jp-sage.jurassic.tube) on theSEARCH-208 Repropage with ajetpack-search/filter-checkboxblock configured atmaxItems = 5. Repro driven viapage.evaluate()injecting a session that retained 7 distinct categories and a follow-up narrowed query whose live aggregation returns only 2 of them.maxItems; the two extra retained-at-zero entries drop off.Verification
In addition to the visual capture above, the new Jest tests in
projects/packages/search/tests/js/search-blocks/filter-checkbox-view.test.jsdrive the samecheckboxFilterItems()code path and assert the cap deterministically — no live ES backend needed.Test output
New tests:
Full search-blocks suite (no regressions):
Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
Acceptance criteria from SEARCH-208, as a reviewer checklist (requires a Jetpack-Search-connected site with indexed content):
For local-env review (no Jetpack-Search index needed), the new Jest tests in
tests/js/search-blocks/filter-checkbox-view.test.jsdrive the same code path and assert the cap deterministically: