Skip to content

Search Blocks: add pre-hydration skeleton to filter-wc-attribute#48677

Merged
kangzj merged 8 commits intotrunkfrom
copilot/fix-filter-wc-attribute-hydration
May 10, 2026
Merged

Search Blocks: add pre-hydration skeleton to filter-wc-attribute#48677
kangzj merged 8 commits intotrunkfrom
copilot/fix-filter-wc-attribute-hydration

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 10, 2026

filter-wc-attribute was the only bucket-driven filter block missing the shared pre-hydration skeleton plumbing. On a deep-linked URL (?pa_color[]=red), the attribute filter wrapper was hidden until JS hydration finished — showing a blank space instead of shimmer rows.

Why

WC attribute filters are typically the longest-loading filter region on a product page — one aggregation per registered pa_* taxonomy. The other bucket-driven filter blocks (filter-checkbox, filter-date, filter-wc-rating) already use the shared skeleton plumbing from #48505 / its follow-ups; this PR brings filter-wc-attribute to parity so deep-linked attribute filter URLs paint the same shimmer rows on first paint instead of a blank gap.

Real-screen before / after

Deep-link /jetpack-search-demo/?pa_color[]=red on the local docker env, captured with JS blocked at the network layer to freeze the pre-hydration window.

Before (trunk) After (this PR)
before after

On trunk both filter-wc-attribute wrappers (Color, Size) render with the literal hidden HTML attribute and stay invisible until JS hydration finishes — so the sidebar shows only the Active-filters chip with empty space below. With this PR the wrappers render with the shared skeleton partial: COLOR/SIZE headings plus shimmer rows, and the pre-selected red checkbox seeded from the URL is already visible.

Changes

filter-wc-attribute/render.php

  • Replaces the inline $has_buckets read with Search_Blocks::pre_hydration_filter_view() (returns has_buckets, is_initial_loading, show_wrapper)
  • Switches wrapper visibility from data-wp-bind--hidden="!state.hasFilterBuckets" to context.wrapperHidden + data-wp-watch="callbacks.syncFilterWrapperVisibility" — the same mechanism used by filter-checkbox / filter-date / filter-wc-rating
  • Includes filter-skeleton-partial.php when is_initial_loading is true
  • Preserves the existing $all_selected_on_paint logic (guards "All filters applied" state), now short-circuited behind $view['has_buckets']

The SCSS was already complete — style.scss had @include skeleton.shimmer and @include skeleton.filter-rows.

Filter_Wc_Attribute_Render_Test.php (new)

Six render-integration tests including the primary regression guard:

// ?pa_color[]=red triggers is_initial_loading() → true
$markup = $this->render_with_skeleton( array( 'attributeTaxonomy' => 'pa_color' ) );
$this->assertStringContainsString( 'jetpack-search-filter__list--skeleton', $markup );
// Wrapper must be visible while skeleton is up — strict regex so
// `data-wp-bind--hidden` / `wrapperHidden` substrings can't false-positive.
$this->assertSame( 0, preg_match( '/<div[^>]*\s+hidden(?=\s|\/|>|=)/', $markup ) );

Test plan

  • composer phpunit in projects/packages/search/ — 354 tests, 772 assertions, all green
  • pnpm test-scripts in projects/packages/search/ — 540 tests across 47 suites, all green
  • PHPCS clean on all modified files
  • Browser sanity check on the local docker env (?pa_color[]=red deep-link) shows the shimmer rows in the attribute filter wrapper

Fixes RSM-2809.

Copilot AI changed the title [WIP] Fix filter-wc-attribute pre-hydration skeleton parity Search Blocks: add pre-hydration skeleton to filter-wc-attribute May 10, 2026
Copilot finished work on behalf of kangzj May 10, 2026 01:35
Copilot AI requested a review from kangzj May 10, 2026 01:35
@kangzj kangzj requested a review from Copilot May 10, 2026 01:41
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 10, 2026

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 copilot/fix-filter-wc-attribute-hydration branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack copilot/fix-filter-wc-attribute-hydration

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

@github-actions github-actions Bot added [Package] Search Contains core Search functionality for Jetpack and Search plugins [Status] In Progress [Tests] Includes Tests labels May 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 10, 2026

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 🤖


🔴 Action required: Please include detailed testing steps, explaining how to test your change, like so:

## Testing instructions:

* Go to '..'
*

🔴 Action required: We would recommend that you add a section to the PR description to specify whether this PR includes any changes to data or privacy, like so:

## Does this pull request change what data or activity we track or use?

My PR adds *x* and *y*.

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!

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label May 10, 2026

This comment was marked as outdated.

@jp-launch-control
Copy link
Copy Markdown

jp-launch-control Bot commented May 10, 2026

Code Coverage Summary

Coverage changed in 3 files.

File Coverage Δ% Δ Uncovered
projects/packages/search/src/search-blocks/blocks/filter-skeleton-partial.php 13/13 (100.00%) 100.00% -13 💚
projects/packages/search/src/search-blocks/class-search-blocks.php 291/423 (68.79%) 4.49% -19 💚
projects/packages/search/src/search-blocks/blocks/filter-wc-attribute/render.php 67/81 (82.72%) 82.72% -62 💚

Full summary · PHP report · JS report

@kangzj
Copy link
Copy Markdown
Contributor

kangzj commented May 10, 2026

@claude review plz

@claude

This comment has been minimized.

@kangzj

This comment has been minimized.

Copilot AI and others added 3 commits May 11, 2026 09:57
- Replace inline `$has_buckets` derivation with `Search_Blocks::pre_hydration_filter_view()`
- Use `Search_Blocks::emit_filter_wrapper_context()` for wrapper context
- Switch from `!state.hasFilterBuckets` to `context.wrapperHidden` + `syncFilterWrapperVisibility`
- Include `filter-skeleton-partial.php` when `is_initial_loading` is true
- Add `Filter_Wc_Attribute_Render_Test.php` with 6 render tests
- Note: style.scss already had the necessary skeleton mixin includes

Closes #48675

Agent-Logs-Url: https://github.com/Automattic/jetpack/sessions/b14b45fa-935e-469e-9205-88393b0e2963

Co-authored-by: kangzj <1425433+kangzj@users.noreply.github.com>
- Replace assertStringContainsString('hidden', ...) and
  assertStringNotContainsString(' hidden', ...) with a strict regex on the
  opening div so the assertion can't be satisfied by data-wp-bind--hidden /
  aria-hidden / wrapperHidden, and isn't sensitive to indentation
  whitespace before the bare hidden attribute. Mirrors the canonical
  Clear_Filters_Render_Test pattern.
- Guard tearDownAfterClass via WP_Block_Type_Registry::is_registered() so
  the early-return path in setUpBeforeClass (WP < 6.5) doesn't leave us
  calling unregister on an unregistered block and tripping failOnNotice.

Addresses Copilot review comments #3214166225, #3214166229, #3214166232.
@kangzj kangzj force-pushed the copilot/fix-filter-wc-attribute-hydration branch from def9099 to ed89c24 Compare May 10, 2026 21:57
@kangzj kangzj removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label May 10, 2026
@kangzj

This comment has been minimized.

@kangzj

This comment has been minimized.

@claude

This comment has been minimized.

This comment has been minimized.

Copilot finished work on behalf of kangzj May 10, 2026 22:09
@kangzj

This comment has been minimized.

@kangzj kangzj added [Status] Needs Team Review Obsolete. Use Needs Review instead. and removed [Status] In Progress labels May 10, 2026
@kangzj kangzj marked this pull request as ready for review May 10, 2026 22:29
@github-actions github-actions Bot added [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels May 10, 2026
@kangzj kangzj changed the title Search Blocks: add pre-hydration skeleton to filter-wc-attribute Search Blocks: narrow pre-hydration skeleton to filter-wc-attribute May 10, 2026
WC attribute filters are the longest-loading filter region on a product
page (one aggregation per registered pa_* taxonomy, often 3-5+ on a
typical shop). The other filter blocks resolve their single aggregation
in one fast call, so the wrapper-hidden-until-buckets pattern they used
pre-#48505 doesn't cause a layout shift the visitor would notice.

- filter-checkbox / filter-date / filter-wc-rating: drop
  pre_hydration_filter_view + emit_filter_wrapper_context + the skeleton
  partial include. Restore the inline $has_buckets derivation and revert
  the wrapper binding to !state.hasFilterBuckets + a conditional literal
  hidden attribute on first paint.
- filter-checkbox/style.scss, filter-date/style.scss,
  filter-wc-rating/style.scss: drop @use "../skeleton" and the
  skeleton.shimmer / skeleton.filter-rows @includes.
- _skeleton.scss, filter-skeleton-partial.php: docstrings updated to
  reflect that only filter-wc-attribute consumes them now.
- filter-wc-attribute: unchanged (keeps the skeleton plumbing this PR
  originally added for it).
@kangzj

This comment has been minimized.

@kangzj

This comment has been minimized.

@claude

This comment has been minimized.

This comment has been minimized.

Copilot finished work on behalf of kangzj May 10, 2026 22:58
claude[bot] flagged the docblock on test_wrapper_uses_context_wrapper_hidden_binding
as stale after the narrowing — it claimed parity with filter-checkbox / filter-date,
which is no longer true since those reverted to !state.hasFilterBuckets. Rewrite it
to call out filter-wc-attribute as the only block still on the wrapperHidden
plumbing and to note why (single aggregation resolves fast for the others).
@kangzj

This comment has been minimized.

@kangzj

This comment has been minimized.

@kangzj
Copy link
Copy Markdown
Contributor

kangzj commented May 10, 2026

🤖 Review-cycle summary (narrowing iteration) — 402bcd5a8f63c6be026c9b

2 rounds on the narrowed scope; CI green (25/25 required checks pass, 6 skipping); claude[bot] and copilot-swe-agent both signed off after their flagged items were addressed.

What changed during this loop iteration

Commits added:

  • 402bcd5a8f6 — Search Blocks: narrow pre-hydration skeleton to filter-wc-attribute (the user-directed scope change)
  • 775420ef708 — Fix stale comments after narrowing skeleton scope (pushed by copilot-swe-agent[bot] during its re-review: store/index.js:1069 JSDoc + filter-wc-attribute/view.js docstring)
  • 3c6be026c9b — Address review: update test docblock to reflect attribute-only scope (claude[bot]'s remaining stale-docblock item at Filter_Wc_Attribute_Render_Test.php:184)

Diff summary: 12 files changed, 52 insertions(+), 59 deletions(-).

Reviewers addressed:

Source Item Resolution
claude[bot] re-review store/index.js:1069 stale comment ("for each filter-checkbox block") Fixed in 775420e (s/filter-checkbox/filter-wc-attribute/)
claude[bot] re-review Filter_Wc_Attribute_Render_Test.php:184–186 stale docblock claiming parity with filter-checkbox / filter-date Fixed in 3c6be02; now spells out filter-wc-attribute as the only block on the wrapperHidden plumbing
claude[bot] re-review Retained-options visibility trade-off (active selection + zero-bucket aggregation → wrapper hides) Documented in the PR body as an "Accepted trade-off" — pre-#48505 behavior; filter-date unaffected by definition
copilot-swe-agent re-review Audit of syncFilterWrapperVisibility / wrapperHidden isolation across the JS store Confirmed safe (context is scoped per block instance by the Interactivity API); also caught and fixed the view.js docstring in 775420e

Unaddressed (flagged for owner): None.

CI: all 25 required checks pass on 3c6be026c9b.

@kangzj kangzj removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Status] In Progress labels May 10, 2026
Per Jasper's clarification, the loading skeleton is needed for filter-wc-attribute
*and* the other bucket-driven filter blocks (filter-checkbox, filter-date,
filter-wc-rating) were already working as expected with their own skeleton plumbing
— they should not have been changed.

Reverts:
- 3c6be02 (test docblock change predicated on the narrowing)
- 775420e (copilot-swe-agent's stale-comment fixes that only made sense in the
  narrowed world)
- 402bcd5 (the narrowing itself)

Net effect: PR returns to its original goal — bring filter-wc-attribute to parity
with filter-checkbox / filter-date / filter-wc-rating's existing pre-hydration
skeleton plumbing. The 3 non-attribute blocks are untouched from trunk.
@kangzj kangzj changed the title Search Blocks: narrow pre-hydration skeleton to filter-wc-attribute Search Blocks: add pre-hydration skeleton to filter-wc-attribute May 10, 2026
@kangzj
Copy link
Copy Markdown
Contributor

kangzj commented May 10, 2026

Course-correction from Jasper: the narrowing direction (commit 402bcd5 + follow-ups) was a misread of the original instruction. filter-wc-attribute needs the loading skeleton just like the other bucket-driven filter blocks — the original PR's intent — and filter-checkbox / filter-date / filter-wc-rating were already working as expected, so they should not have been touched.

Reverted in 63cf38c (Revert narrowing: keep skeleton SSR on all bucket-driven filter blocks). The PR is back to its original goal of bringing filter-wc-attribute to parity with the existing skeleton plumbing.

PR title + body restored. All 354 PHP tests + 540 JS tests pass locally; PHPCS clean.

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label May 10, 2026
@kangzj kangzj merged commit 271b167 into trunk May 10, 2026
74 of 75 checks passed
@kangzj kangzj deleted the copilot/fix-filter-wc-attribute-hydration branch May 10, 2026 23:56
@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] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Status] Needs Team Review Obsolete. Use Needs Review instead. labels May 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Search Contains core Search functionality for Jetpack and Search plugins [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.

3 participants