Skip to content

Conversation

@kangzj
Copy link
Contributor

@kangzj kangzj commented Oct 30, 2025

Proposed changes:

This PR modifies the Instant Search build configuration to make it compatible with the WordPress Interactivity API by allowing WordPress to control CSS loading instead of webpack's automatic injection.

Changes:

  • Configure MiniCssExtractPlugin to use static filenames without contenthash
  • Disable webpack CSS runtime loading (runtime: false)
  • Disable MiniCssWithRtlPlugin (WordPress Assets class handles RTL detection)
  • Add css_path parameter to Assets::register_script() to enqueue CSS via WordPress

Why these changes?

The WordPress Interactivity API requires CSS to be properly enqueued in the <head> before JavaScript hydration occurs. Previously, webpack was dynamically injecting CSS when the async chunk loaded, which:

  1. Created timing issues with Interactivity API hydration
  2. Wasn't following WordPress plugin best practices for asset loading

Now CSS is:

  • Extracted by webpack to a static filename (jp-search.chunk-main-payload.css)
  • Enqueued by WordPress with proper versioning (?ver=<ver>)
  • Loaded in <head> before any JavaScript executes
  • No longer auto-injected by webpack

Other information:

  • Have you written new tests for your changes, if applicable? - No new tests needed; existing functionality maintained with different loading mechanism
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

p1753090979383509-slack-C02ME06LF

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

No, this PR only changes how CSS assets are loaded. No tracking or data collection changes.

Testing instructions:

Prerequisites

  • Jetpack local dev env
  • Instant Search enabled

Testing Steps

  1. Build the assets:
cd projects/packages/search
pnpm run build-instant
  1. Verify CSS files are generated without contenthash:
ls -la build/instant-search/*.css
  1. You should see:
  • jp-search.chunk-main-payload.css
  • jp-search.chunk-main-payload.rtl.css
    (No version hash in the filename itself)
  1. Check that webpack doesn't include CSS loading runtime:
    grep -c "miniCssF" build/instant-search/jp-search.js

  2. Should return 0 (no CSS loading code)

  3. Test in WordPress:

  • Activate Jetpack Search with Instant Search enabled
  • Load a page with the search overlay
  • Open browser DevTools
  1. Verify CSS loading:
  • Network tab: Look for jp-search.chunk-main-payload.css
  • Should be loaded from WordPress (check URL includes ?ver=)
  • Should only load once (no duplicate requests)
  1. Verify in page source:
  • View page source (Cmd/Ctrl + U)
  • Search for jp-search.chunk-main-payload.css
  • Should appear in as a tag enqueued by WordPress
  • Should NOT be added dynamically by JavaScript
  1. Test build artifacts:
  • Check that no CSS loading errors appear in console
  • Verify dynamic chunk (jp-search.chunk-main-payload.js) loads successfully
  • Confirm search functionality works identically to before
kangzj and others added 2 commits October 30, 2025 17:17
Changes webpack configuration to disable automatic CSS injection and allow
WordPress to control CSS loading via wp_enqueue_style, making Instant Search
compatible with the WordPress Interactivity API.

Changes:
- Configure MiniCssExtractPlugin with static filenames (no contenthash)
- Disable CSS runtime loading (runtime: false)
- Disable MiniCssWithRtlPlugin (WordPress handles RTL)
- Add css_path to Assets::register_script() for WordPress CSS enqueuing

This ensures CSS loads in <head> before JavaScript hydration, preventing
duplicate loading while maintaining proper cache busting through WordPress
versioning.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Oct 30, 2025

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 add/wordpress-css-control-for-instant-search branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/wordpress-css-control-for-instant-search

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 labels Oct 30, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 30, 2025

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 a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ 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!

@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 Oct 30, 2025
@jp-launch-control
Copy link

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/search/src/instant-search/class-instant-search.php 221/332 (66.57%) -0.40% 2 ❤️‍🩹

Full summary · PHP report · JS report

@kangzj kangzj marked this pull request as ready for review October 30, 2025 21:03
@kangzj kangzj added [Type] Task [Status] Needs Team Review Obsolete. Use Needs Review instead. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Oct 30, 2025
@kangzj kangzj requested review from a team and luisherranz October 30, 2025 21:05
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] In Progress [Status] Needs Team Review Obsolete. Use Needs Review instead. [Type] Task

2 participants