Agents Manager: Add filter to skip enqueue in block editor contexts#47248
Agents Manager: Add filter to skip enqueue in block editor contexts#47248
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
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! |
Code Coverage SummaryCoverage changed in 1 file.
|
1763cb3 to
afb918f
Compare
There was a problem hiding this comment.
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_editorfilter gate inshould_enqueue_script()to allow skipping enqueue on block editor screens. - Add a
jetpack-mu-wpcomchangelog 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.
projects/packages/jetpack-mu-wpcom/src/features/agents-manager/class-agents-manager.php
Show resolved
Hide resolved
projects/packages/jetpack-mu-wpcom/src/features/agents-manager/class-agents-manager.php
Show resolved
Hide resolved
There was a problem hiding this comment.
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.
projects/packages/jetpack-mu-wpcom/src/features/agents-manager/class-agents-manager.php
Show resolved
Hide resolved
projects/packages/jetpack-mu-wpcom/src/features/agents-manager/class-agents-manager.php
Show resolved
Hide resolved
There was a problem hiding this comment.
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.
projects/packages/jetpack-mu-wpcom/tests/php/features/agents-manager/Agents_Manager_Test.php
Outdated
Show resolved
Hide resolved
projects/packages/jetpack-mu-wpcom/tests/php/features/agents-manager/Agents_Manager_Test.php
Outdated
Show resolved
Hide resolved
| if ( $this->is_block_editor() && ! apply_filters( 'agents_manager_enqueue_in_block_editor', true ) ) { | ||
| return false; |
There was a problem hiding this comment.
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.
5d58577 to
47c28ec
Compare
|
@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. |
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>
47c28ec to
7008746
Compare
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
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.
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>
Related to WOOAI-332
Add
agents_manager_enqueue_in_block_editorfilter 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:
agents_manager_enqueue_in_block_editorfilter 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:
Agents-manager hooks into admin_enqueue_scripts so when the editor assets endpoint fires
admin_enqueue_scriptsit enqueues thegutenbergvariant.Later in the frontend this is processed, leading to a double chat UI interface: one per the original
wp-adminvariant and one for the newgutenbergvariant due to this dynamic assets loading for the SPA.Other information:
Jetpack product discussion
None.
Does this pull request change what data or activity we track or use?
No.
Testing instructions:
Changelog