Skip to content

fix: Reinstate Jetpack assets to editor assets endpoint#44274

Merged
dcalhoun merged 6 commits intotrunkfrom
fix/reinstate-jetpack-assets-to-editor-assets-endpoint
Jul 15, 2025
Merged

fix: Reinstate Jetpack assets to editor assets endpoint#44274
dcalhoun merged 6 commits intotrunkfrom
fix/reinstate-jetpack-assets-to-editor-assets-endpoint

Conversation

@dcalhoun
Copy link
Member

@dcalhoun dcalhoun commented Jul 10, 2025

#44093 fixed de-registering of assets not present on the allow list. However, it was overlooked that certain Jetpack assets were then erroneously excluded.

Namely, the jetpack-blocks-editor assets were excluded as their jetpack-blocks-assets-base-url dependency was also excluded. The latter was excluded as it is an "inline" script without a src attribute. The lack of a src meant the path-based exclusion erroneously de-registered the script.

Using a handle-based exclusion means that both inline and external scripts are correct assessed by the plugin filtering logic.

Proposed changes:

Replace asset path-based exclusion logic with asset handle-based exclusion logic.

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

0b1591ec5132-linear-project

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

No

Testing instructions:

  1. Create a WPCOM site.
  2. Apply these Jetpack changes to your site (see comment).
  3. Make a request to the /wpcom/v2/sites/<site_id>/editor-assets endpoint for the WPCOM site—via API Console, curl, etc.
  4. Verify the 200 response contains the jetpack-blocks-editor-js script.

dcalhoun added 2 commits July 10, 2025 12:37
Recent changes fixed de-registering of assets not present on the allow
list. However, it was overlooked that certain Jetpack assets were then
erroneously excluded.

Namely, the `jetpack-blocks-editor` assets were excluded as their
`jetpack-blocks-assets-base-url` dependency was also excluded. The
latter was excluded as it is an "inline" script without a `src`
attribute. The lack of a `src` meant the path-based exclusion
erroneously de-registered the script.

Using a handle-based exclusion means that both inline and external
scripts are correct assessed by the plugin filtering logic.
@dcalhoun dcalhoun added Bug When a feature is broken and / or not performing as intended [Status] In Progress [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests labels Jul 10, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jul 10, 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 fix/reinstate-jetpack-assets-to-editor-assets-endpoint branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/reinstate-jetpack-assets-to-editor-assets-endpoint

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

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!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: August 5, 2025
    • Code freeze: August 4, 2025

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@jp-launch-control
Copy link

jp-launch-control bot commented Jul 10, 2025

Code Coverage Summary

Coverage changed in 2 files.

File Coverage Δ% Δ Uncovered
projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-block-editor-assets.php 128/134 (95.52%) -0.69% 1 ❤️‍🩹
projects/plugins/jetpack/modules/photon-cdn.php 50/112 (44.64%) 0.89% -1 💚

Full summary · PHP report · JS report

Comment on lines -46 to -61
/**
* Mock function for block editor assets.
* This provides minimal required assets without loading actual files.
*/
public function mock_block_editor_assets() {
// Register minimal mock assets that don't require actual files
wp_register_script( 'mock-editor-script', 'http://example.org/plugins/jetpack/mock-editor.js', array(), '1.0', true );
wp_register_style( 'mock-editor-style', 'http://example.org/plugins/jetpack/mock-editor.css', array(), '1.0' );
wp_register_script( 'disallowed-plugin-script', 'http://example.org/plugins/disallowed-plugin/script.js', array(), '1.0', true );
wp_register_script( 'disallowed-plugin-style', 'http://example.org/plugins/disallowed-plugin/style.css', array(), '1.0', true );

// Enqueue our mock assets
wp_enqueue_script( 'mock-editor-script' );
wp_enqueue_style( 'mock-editor-style' );
wp_enqueue_script( 'disallowed-plugin-script' );
wp_enqueue_style( 'disallowed-plugin-style' );
Copy link
Member Author

Choose a reason for hiding this comment

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

Relocated these mocks to be co-located with related test cases to better communicate intent.

Comment on lines -22 to -28
const ALLOWED_PLUGINS = array(
'/plugins/gutenberg/', // Default plugin location
'/plugins/gutenberg-core/', // WPCOM Simple site location
'/plugins/jetpack/', // Default plugin location
'/plugins/jetpack-dev/', // Used for loading in-progress work
'/mu-plugins/jetpack-mu-wpcom-plugin/', // WPCOM Simple site location
'/mu-plugins/wpcomsh/', // WoA helpers, including Jetpack assets in vendor directories
Copy link
Member Author

Choose a reason for hiding this comment

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

The path-based allow list meant that inline script tags were erroneously disallowed, as inline scripts do not have a path assigned to a src attribute.

@dcalhoun dcalhoun marked this pull request as ready for review July 10, 2025 20:53
@dcalhoun dcalhoun requested review from Copilot and nbradbury July 10, 2025 20:53
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

This PR replaces the previous path-based asset exclusion in the block editor assets endpoint with a handle-prefix–based approach to ensure inline and external Jetpack assets are correctly retained.

  • Switched from URL substring checks to handle-prefix checks for asset whitelisting in the endpoint class.
  • Renamed helper methods and updated constants (ALLOWED_PLUGIN_HANDLE_PREFIXES, is_core_or_gutenberg_asset, is_allowed_plugin_handle).
  • Updated tests to mock and verify allowed, disallowed, and WPCOM Gutenberg assets using the new handle-based logic, and added a changelog entry.

Reviewed Changes

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

File Description
projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-block-editor-assets.php Swapped path-based exclusion for handle-prefix logic and renamed related methods/constants.
projects/plugins/jetpack/tests/php/core-api/wpcom-endpoints/WPCOM_REST_API_V2_Endpoint_Block_Editor_Assets_Test.php Removed old mocks, added new handle-based tests and mock methods.
projects/plugins/jetpack/changelog/fix-reinstate-jetpack-assets-to-editor-assets-endpoint Added a patch-level changelog entry.

dcalhoun added 2 commits July 11, 2025 08:25
The designation was erroneous to start.
Avoid confusion regarding the purpose of each allowed handle. Namely,
the usage of `wp-` which is used by core WordPress scripts, but also
some WPCOM and Jetpack scripts too.
@dcalhoun dcalhoun requested review from kean and removed request for nbradbury July 11, 2025 14:05
Copy link

@kean kean left a comment

Choose a reason for hiding this comment

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

I reviewed it, and to the best of my knowledge, the changes look good.

@dcalhoun dcalhoun merged commit 877c912 into trunk Jul 15, 2025
68 checks passed
@dcalhoun dcalhoun deleted the fix/reinstate-jetpack-assets-to-editor-assets-endpoint branch July 15, 2025 13:26
@github-actions github-actions bot added this to the jetpack/14.9 milestone Jul 15, 2025
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 [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants