-
Notifications
You must be signed in to change notification settings - Fork 839
feat: Filter editor assets endpoint with exclude parameter #45715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: refactor/improve-editor-assets-endpoint
Are you sure you want to change the base?
feat: Filter editor assets endpoint with exclude parameter #45715
Conversation
Allow omitting assets from the endpoint return by handle. Helpful for omitting problematic plugins or those already provided by the client.
|
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! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
These keys are explicitly set in the callback passed to `with_absolute_urls()` a few lines above.
| // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset -- Keys are guaranteed by callback above | ||
| 'scripts' => $html['scripts'], | ||
| // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset -- Keys are guaranteed by callback above |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These values are inaccessible to Phan due to the opaque callback passed to with_absolute_urls. That callback explicitly defines these keys,.
| * @param array $exclude_rules Array of exclusion rules. | ||
| * @return string The filtered HTML content. | ||
| */ | ||
| private function filter_conditional_comments( $html, $tag_name, $url_attribute, $exclude_rules ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function's complexity and usage of regex is unfortunate, but necessary as DOMDocument cannot access the HTML tags within the conditional HTML comment.
Note
The builds atop of and targets #45714.
Allow omitting assets from the endpoint return by handle. Helpful for omitting problematic plugins or those already provided by the client. Omissions must occur on the captured HTML, as unregistering the assets would lead to also omitting assets that declare them as dependencies. E.g. unregistering
reactmay cause a plugin's script to be discarded from the printed scripts due to the missingreactdependency.This will be used by the GutenbergKit mobile app editor to retrieve plugin assets only. GutenbergKit includes Gutenberg's
@wordpressmodules in its own bundle and does not need to fetch these assets.An example request is
https://[site_domain]/?rest_route=/wpcom/v2/editor-assets?exclude=core,gutenberg.Proposed changes:
excludeparameter for listing plugins to exclude."core"exclusion keyword for excluding WordPress core-provided block editor assets (i.e., the@wordpressmodules used by the block editor).stylesandscriptsreturn values withDOMDocumentfor consistent results.DOMDocumentcannot recognize the HTML within them E.g.,<!--[if lt IE 8]>[script_or_link]<![endif]-->.Other information:
Jetpack product discussion
p1761568270564209-slack-C08UN8YN6KW
Does this pull request change what data or activity we track or use?
No
Testing instructions:
See wordpress-mobile/GutenbergKit#209.
Additionally, one can perform API Console or
curlrequests to the endpoint with and without theexcludeparameter to test and observe the results.