Skip to content
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

Ensure services that are delayed and have requirements are scheduled correctly #6548

Merged
merged 7 commits into from
Aug 23, 2021

Conversation

schlessera
Copy link
Collaborator

Summary

The code that was dealing with service requirements was missing logic for the scenario where the service has requirements AND it is Delayed itself. In that case, and if the delay of the service being checked is later than the delay of the requirements, that delay would not have been respected.

This PR changes up the logic to make it clearer when registration is scheduled.

Checklist

  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

@schlessera schlessera added the Bug Something isn't working label Aug 18, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Aug 18, 2021

Plugin builds for 1e9f460 are ready 🛎️!

@schlessera schlessera changed the title Ensure services that are delayed and have requirements are schedulecorrectly Ensure services that are delayed and have requirements are scheduled correctly Aug 19, 2021
@schlessera
Copy link
Collaborator Author

@pierlon The test for the polyfills fails on WP 4.9.

From what I could find out, it looks like is_gutenberg_page() is not defined in that scenario, which therefore makes the registration of the Polyfills service bail early here: https://github.com/ampproject/amp-wp/blame/develop/src/Admin/Polyfills.php#L70-L71

Not sure why this test didn't fail before. Am I misunderstanding something here?

@westonruter westonruter added this to the v2.1.4 milestone Aug 19, 2021
@westonruter
Copy link
Member

From what I could find out, it looks like is_gutenberg_page() is not defined in that scenario, which therefore makes the registration of the Polyfills service bail early here: https://github.com/ampproject/amp-wp/blame/develop/src/Admin/Polyfills.php#L70-L71

Bail early? But the check is function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() so if the function doesn't exist then it should not return.

It seems rather that is_gutenberg_page() exists and the function is returning true for some reason?

In WordPress 4.9 the version of Gutenberg installed is 4.9.0:

case "$WP_VERSION" in
"4.9")
gb_version="4.9.0"
;;

This is being done: https://github.com/ampproject/amp-wp/pull/6548/checks?check_run_id=3368405984#step:16:6

The is_gutenberg_page() function is as follows: https://github.com/WordPress/gutenberg/blob/v4.9.0/gutenberg.php#L111-L146

@westonruter
Copy link
Member

There we go. The issue appears to be that the test was calling register method:

/**
* Runs on instantiation.
*/
public function register() {
if ( function_exists( 'get_current_screen' ) ) {
$screen = get_current_screen();
if ( ! empty( $screen->is_block_editor ) ) {
return;
}
}
// Applicable to Gutenberg v5.5.0 and older.
if ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) {
return;
}
$this->register_shimmed_scripts( wp_scripts() );
$this->register_shimmed_styles( wp_styles() );
}

This is calling wp_scripts() and wp_styles() which instantiates WP_Scripts and WP_Styles if the globals aren't already instantiated. Nevertheless, immediately after calling register the test was overriding the WP_Scripts and WP_Styles globals so that they were devoid of anything that the register method did with register_shimmed_scripts and register_shimmed_styles:

global $wp_scripts, $wp_styles;
$this->instance->register();
$wp_scripts = new WP_Scripts();
$wp_styles = new WP_Styles();

It seems that this action is being triggered unnecessarily:

/** This action is documented in includes/class-amp-theme-support.php */
do_action( 'amp_register_polyfills' );

Since the register method was manually invoked above. It doesn't seem this action results in register being called again.

@pierlon
Copy link
Contributor

pierlon commented Aug 22, 2021

Thanks for looking into why that test was failing @westonruter 🙌. Great detective work.

Copy link
Contributor

@pierlon pierlon left a comment

Choose a reason for hiding this comment

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

Thanks for identifying the bug @schlessera.

@westonruter westonruter merged commit d3a85fa into develop Aug 23, 2021
@westonruter westonruter deleted the fix/service-registration-dependencies-iteration branch August 23, 2021 21:26
@westonruter westonruter modified the milestones: v2.1.4, v2.2 Aug 23, 2021
@bartoszgadomski
Copy link
Contributor

QA passed

I did run smoke tests and didn't notice any issues.

@westonruter westonruter added the Changelogged Whether the issue/PR has been added to release notes. label Dec 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Changelogged Whether the issue/PR has been added to release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants