-
Notifications
You must be signed in to change notification settings - Fork 466
feat: enqueued asset changes #3169
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: develop
Are you sure you want to change the base?
feat: enqueued asset changes #3169
Conversation
| 'description' => __( 'The loading strategy to use on the script tag', 'wp-graphql' ), | ||
| 'resolve' => static function ( \_WP_Dependency $script ) { | ||
| if ( ! isset( $script->extra['group'] ) ) { | ||
| return 0; |
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.
Avoid too many return statements within this method.
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.
Should this be on the interface?
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.
Also, defaulting to HEADER only seems true for scripts, but per the above link, a false value is NO_GROUP. Not sure if that's a helpful demarcation for non-script assets, but it does respect WP as source-of-truth
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.
Gotcha, I've copied the group field to the EnqueuedAsset type with a return type to Integer. Then renamed the group field to location in the EnqueuedScript file.
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.
Not sure I follow the change. What is the difference between group and location?
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.
group is the group level that can be applied to all _WP_Dependencies, and location is the enum representation of this value exclusive to scripts being either HEADER for 0 and FOOTER for 1.
| * | ||
| * @return array | ||
| */ | ||
| public static function get_enqueued_scripts_handles( $queue ) { |
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.
Similar blocks of code found in 2 locations. Consider refactoring.
| return array_values( array_unique( $handles ) ); | ||
| } | ||
|
|
||
| public static function get_enqueued_styles_handles( $queue ) { |
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.
Similar blocks of code found in 2 locations. Consider refactoring.
| * | ||
| * @return array | ||
| */ | ||
| public static function get_enqueued_scripts_handles( $queue ) { |
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.
Function get_enqueued_scripts_handles has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
| 'resolve' => static function ( $source, $args, $context, $info ) { | ||
| // Simulate WP template rendering | ||
| ob_start(); | ||
| wp_head(); |
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 will be incompatible with eventual FSE support, and break several existing WPGraphQL extensions (e.g. seo). I haven't reviewed the PR for real, so without knowing the full goal I gotta hope there's a different way to accomplish this.
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.
We'll maybe not the FSE but plain-old Gutenburg and editor pages, yes.
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.
Also it runs on the resolvers for both enqueuedStyles and enqueuedScripts, which means these do_action() and apply_filters() are getting triggered multiple times too... What's the performance hit with this change?
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.
Nothing that I've noticed, but I'm just using WC and some WC premium plugins, and while WC emits a lot of localize scripts for their pages I've haven't seen any slow downs in the query speed due to this change.
| 'description' => __( 'The loading group to which this asset belongs.', 'wp-graphql' ), | ||
| 'resolve' => static function ( $asset ) { | ||
| if ( ! isset( $asset->extra['group'] ) ) { | ||
| return 0; |
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.
Avoid too many return statements within this method.
| return 0; | ||
| } | ||
|
|
||
| return absint( $asset->extra['group'] ); |
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.
Avoid too many return statements within this method.
| * | ||
| * @return string[] | ||
| */ | ||
| public static function get_enqueued_asset_handles( array $queue, $wp_assets ) { |
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.
Function get_enqueued_asset_handles has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
1f70926 to
af5bbc5
Compare
| * | ||
| * @return string[] | ||
| */ | ||
| public static function get_enqueued_asset_handles( array $queue, $wp_assets ) { |
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.
Function get_enqueued_asset_handles has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
af5bbc5 to
6188d78
Compare
| * | ||
| * @return string[] | ||
| */ | ||
| public static function flatten_enqueued_assets_list( array $queue, $wp_assets ) { |
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.
Function flatten_enqueued_assets_list has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
…ution implemented
3872ec5 to
d7b71a5
Compare
|
Code Climate has analyzed commit f6adc45 and detected 8 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
Cherrypicked from wp-graphql#3169 Co-authored-by: Geoff Taylor <[email protected]>
What does this implement/fix? Explain your changes.
enqueuedScripts, andenqueuedStylesfield on theContentNodeto better simulate the rendering of a content node a WordPress theme, as well as sorting the results in the correct order for rendering.The primary purpose of this change is to enable and simplify the process of render an editor page in a headless application on a 1:1 scale with the WordPress theme. CSS/JS scripts and all.
EnqueuedScripttype's newlocationfield.groupfield to theEnqueuedAssettype.locationfield to theEnqueuedScripttype.AllMoved to chore: WPGraphQLTestCase constant usage updated for extendability #3191self::IS_NULL,self::IS_FALSY,self::NOT_NULL, andself::NOT_FALSYcalls in tests replaced withstatic::IS_NULL,static::IS_FALSY,static::NOT_NULLandstatic::NOT_FALSYto ensure the youngest definition is always returned.Does this close any currently open issues?
Any relevant logs, error output, GraphiQL screenshots, etc?
Any other comments?
…
Where has this been tested?
Operating System: …
WordPress Version: …