Skip to content

Search Blocks: cap filter-checkbox list at Maximum items after session retention (SEARCH-208) - #48989

Merged
kangzj merged 1 commit into
trunkfrom
sage/search-208-filter-checkbox-cap-maxitems
May 20, 2026
Merged

kangzj merged 1 commit into
trunkfrom
sage/search-208-filter-checkbox-cap-maxitems

Conversation

@kangzj

@kangzj kangzj commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

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 in checkboxFilterItems() to Math.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.
  • Three new tests in projects/packages/search/tests/js/search-blocks/filter-checkbox-view.test.js covering the cap, the default-of-10 fallback, and the floor-at-1 coercion.

Date filter unaffected — mergeRetainedFilterOptions() already skips filterType === 'date' and dateFilterItems() slices in-loop.

Screenshots

Captured against the local docker env (https://jp-sage.jurassic.tube) on the SEARCH-208 Repro page with a jetpack-search/filter-checkbox block configured at maxItems = 5. Repro driven via page.evaluate() injecting a session that retained 7 distinct categories and a follow-up narrowed query whose live aggregation returns only 2 of them.

Before (bug) After (fix)
before after
7 items rendered (News 4, Reviews 2, Food 0, Guides 0, Opinion 0, Sports 0, Travel 0) — exceeds the configured maximum. 5 items rendered (News 4, Reviews 2, Food 0, Guides 0, Opinion 0) — capped at 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.js drive the same checkboxFilterItems() code path and assert the cap deterministically — no live ES backend needed.

Test output
$ pnpm jest tests/js/search-blocks/filter-checkbox-view.test.js

Test Suites: 1 passed, 1 total
Tests:       26 passed, 26 total

New tests:

  • caps the rendered list at maxItems when retained options push it past the limit
  • falls back to a maxItems default of 10 when the config omits it
  • coerces a maxItems below 1 up to 1 so the slice never empties the list

Full search-blocks suite (no regressions):

Test Suites: 21 passed, 21 total
Tests:       494 passed, 494 total

Related product discussion/links

  • SEARCH-208 — Linear issue
  • #48593 (SEARCH-178) — introduced session-retained options that this change caps

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):

  • Add a Filter by Category block to a search-results page and set Maximum items = 5.
  • Run a broad search query so the category aggregation returns 5 categories.
  • Refine the query so the live aggregation returns only 2 of those categories.
  • Confirm the checkbox list still shows at most 5 items (not 7).
  • Confirm the 2 live (non-zero count) categories appear in the list, with retained-but-now-empty entries filling remaining slots and dropping off first.
  • Confirm selecting a category beyond the cap still surfaces via the active-filters pill row.
  • Confirm the date filter is unchanged.

For local-env review (no Jetpack-Search index needed), the new Jest tests in tests/js/search-blocks/filter-checkbox-view.test.js drive the same code path and assert the cap deterministically:

pnpm --filter @automattic/jetpack-search jest tests/js/search-blocks/filter-checkbox-view.test.js

…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.
@kangzj kangzj added Bug When a feature is broken and / or not performing as intended [Status] In Progress [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Package] Search Contains core Search functionality for Jetpack and Search plugins labels May 20, 2026
@kangzj kangzj self-assigned this May 20, 2026
@kangzj kangzj added Bug When a feature is broken and / or not performing as intended [Status] In Progress [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Package] Search Contains core Search functionality for Jetpack and Search plugins labels May 20, 2026
@github-actions

github-actions Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the sage/search-208-filter-checkbox-cap-maxitems branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack sage/search-208-filter-checkbox-cap-maxitems

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@kangzj

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

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.

@claude

This comment has been minimized.

@jp-launch-control

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/search/src/search-blocks/store/index.js 341/381 (89.50%) 0.03% 0 💚

Full summary · PHP report · JS report

@kangzj
kangzj merged commit 452adef into trunk May 20, 2026
79 of 82 checks passed
@kangzj
kangzj deleted the sage/search-208-filter-checkbox-cap-maxitems branch May 20, 2026 02:08
@github-actions github-actions Bot added [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. and removed [Status] In Progress labels May 20, 2026
@kangzj

kangzj commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

Review-cycle summary — 51e517f873e → merged as 452adefcb80

PR merged before any addressable review feedback landed; loop exits clean after round 2.

What happened during the cycle
  • Round 1 (~02:38 UTC): kickoff comment pinged @claude.
  • @claude posted its review at ~02:40 UTC — "Looks good. No blocking issues." No code changes requested.
  • Required CI: all green (PHP lint matrix, JS tests, E2E search, lint, type-check, coverage). Only "Manage labels and assignees" was pending — non-blocking, not a required check.
  • Branch did not need a rebase — no trunk drift before merge.
  • Merged by @kangzj at 2026-05-20T02:08:57Z as 452adefcb80.

Review threads addressed: none — the only AI review (claude[bot] id 4493735134) was informational with no action items.

Unaddressed human comments flagged for owner: none.

@claude

claude Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kangzj's task in 17s —— View job


Review cycle complete

PR #48989 was merged at 2026-05-20T02:08:57Z as 452adefcb80. No action items remain.

Summary:

  • Review posted at ~02:40 UTC: no blocking issues found
  • All required CI checks passed (PHP lint, JS tests, E2E search, lint, type-check, coverage)
  • No review feedback required code changes
  • Loop exits clean after round 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug When a feature is broken and / or not performing as intended [Package] Search Contains core Search functionality for Jetpack and Search plugins [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant