Skip to content

Agents Manager: Add filter to skip enqueue in block editor contexts#47248

Open
aaronfc wants to merge 4 commits intotrunkfrom
add/agents-manager-block-editor-filter
Open

Agents Manager: Add filter to skip enqueue in block editor contexts#47248
aaronfc wants to merge 4 commits intotrunkfrom
add/agents-manager-block-editor-filter

Conversation

@aaronfc
Copy link
Contributor

@aaronfc aaronfc commented Feb 20, 2026

Related to WOOAI-332

Add agents_manager_enqueue_in_block_editor filter so environments like CIAB can prevent agents-manager from loading in block editor asset requests where it is already running from the parent page.

Proposed changes:

  • Add a new agents_manager_enqueue_in_block_editor filter that allows disabling the gutenberg assets in the editor on demand.

Why is this needed?

CIAB doesn't load the block editor the traditional WordPress way (full page render with <script> tags). Instead, the SPA dynamically fetches block editor dependencies via a REST API call:

  1. GET /wp/v2/editor/assets: PHP fires WordPress hooks (admin_enqueue_scripts, enqueue_block_editor_assets) in a synthetic context, captures everything that was wp_enqueue_script'd into JSON
  2. Frontend loadAssets() takes that JSON and creates real <script> tags in the DOM

Agents-manager hooks into admin_enqueue_scripts so when the editor assets endpoint fires admin_enqueue_scripts it enqueues the gutenberg variant.

Later in the frontend this is processed, leading to a double chat UI interface: one per the original wp-admin variant and one for the new gutenberg variant due to this dynamic assets loading for the SPA.

Other information:

  • Have you written new tests for your changes, if applicable?
  • 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

None.

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

No.

Testing instructions:

  • Test instructions in 3155-ghe-Automattic/ciab-admin

Changelog

  • Generate changelog entries for this PR (using AI).

@github-actions
Copy link
Contributor

github-actions bot commented Feb 20, 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 (WordPress.com Site Helper), and enable the add/agents-manager-block-editor-filter branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack-mu-wpcom-plugin add/agents-manager-block-editor-filter

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
Copy link
Contributor

github-actions bot commented Feb 20, 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 🤖


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 Feb 20, 2026
@jp-launch-control
Copy link

jp-launch-control bot commented Feb 20, 2026

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/jetpack-mu-wpcom/src/features/agents-manager/class-agents-manager.php 234/347 (67.44%) 0.48% -1 💚

Full summary · PHP report

@aaronfc aaronfc self-assigned this Feb 20, 2026
@aaronfc aaronfc force-pushed the add/agents-manager-block-editor-filter branch from 1763cb3 to afb918f Compare February 20, 2026 12:16
@aaronfc aaronfc requested a review from a team February 20, 2026 12:59
@aaronfc aaronfc marked this pull request as ready for review February 20, 2026 13:00
Copilot AI review requested due to automatic review settings February 20, 2026 13:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new WordPress filter to let specific environments (e.g., CIAB) prevent Agents Manager from enqueuing its scripts/styles inside block editor contexts, avoiding duplicate loads when the parent page already provides the UI.

Changes:

  • Add agents_manager_enqueue_in_block_editor filter gate in should_enqueue_script() to allow skipping enqueue on block editor screens.
  • Add a jetpack-mu-wpcom changelog entry documenting the new filter.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
projects/packages/jetpack-mu-wpcom/src/features/agents-manager/class-agents-manager.php Adds the new block-editor enqueue filter check to skip loading Agents Manager assets in editor contexts when desired.
projects/packages/jetpack-mu-wpcom/changelog/add-agents-manager-block-editor-filter Documents the change as a patch-level “added” entry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings February 20, 2026 13:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings February 20, 2026 13:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +264 to +265
if ( $this->is_block_editor() && ! apply_filters( 'agents_manager_enqueue_in_block_editor', true ) ) {
return false;
Copy link
Member

@jom jom Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In https://github.com/Automattic/big-sky-plugin/pull/5700/ and https://github.com/Automattic/big-sky-plugin/pull/5700/, I was going to add a filter, but I think I could make this approach here work if we adjust it like this.

Never mind! I'm going to switch it to agents_manager_enabled_in_block_editor for my filter because it serves a different purpose and then it'll complement this nicely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that an approval then? 🍏 ? @jom

@aaronfc aaronfc force-pushed the add/agents-manager-block-editor-filter branch from 5d58577 to 47c28ec Compare February 24, 2026 13:09
@aaronfc
Copy link
Contributor Author

aaronfc commented Feb 24, 2026

@jom I have added a "Why" section to the PR description. This is because of how SPA loads the editor assets. Feel free to suggest an alternative route, but this approach makes sense to me.

aaronfc and others added 3 commits February 24, 2026 21:12
Add `agents_manager_enqueue_in_block_editor` filter so environments
like CIAB can prevent agents-manager from loading in block editor
asset requests where it is already running from the parent page.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…/class-agents-manager.php

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Verify that should_enqueue_script returns false in block editor
contexts when the new filter is set to false.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 24, 2026 20:13
@aaronfc aaronfc force-pushed the add/agents-manager-block-editor-filter branch from 47c28ec to 7008746 Compare February 24, 2026 20:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 25, 2026 10:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@aaronfc aaronfc requested a review from jom February 25, 2026 11:07
aaronfc added a commit that referenced this pull request Feb 25, 2026
The `agents_manager_enqueue_in_block_editor` filter belongs to a
separate PR (#47248) and should not be mixed into the CIAB variant
changes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[mu wpcom Feature] Agents Manager [Package] Jetpack mu wpcom WordPress.com Features [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. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants