-
Notifications
You must be signed in to change notification settings - Fork 385
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
Fix usage of amp_register_polyfills
hook
#7458
Changes from 2 commits
077523c
378522c
3c17ea9
a931e7a
5dba91a
5343399
ad16781
47c7934
ec2974f
8535112
e7500ab
8fd04db
56daefa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -89,8 +89,9 @@ public function register() { | |||
* Enqueue admin assets. | ||||
*/ | ||||
public function enqueue_scripts() { | ||||
/** This action is documented in includes/class-amp-theme-support.php */ | ||||
thelovekesh marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
do_action( 'amp_register_polyfills' ); | ||||
if ( $this->is_options_menu() ) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, actually maybe this won't work as expected? Let's say you're not on the Settings screen. In this case, the polyfills won't be registered and the result will be possibly that the required scripts are not registered, right? I think the way to address this is to remove the logic here and move it to We have the expected version of React or we're on one of the AMP settings screens. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Since it has amp-wp/src/Admin/ValidationCounts.php Line 78 in 378522c
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
<?php return array('dependencies' => array('wp-api-fetch', 'wp-dom-ready', 'wp-i18n'), 'version' => '29b558177338ddf7e50f'); |
||||
do_action( 'amp_register_polyfills' ); | ||||
} | ||||
|
||||
$asset_file = AMP__DIR__ . '/assets/js/' . self::ASSETS_HANDLE . '.asset.php'; | ||||
$asset = require $asset_file; | ||||
|
@@ -122,12 +123,19 @@ public function enqueue_scripts() { | |||
* screen related to `amp_validation_error` post type (which includes the `amp_validation_error` taxonomy). | ||||
*/ | ||||
protected function maybe_add_preload_rest_paths() { | ||||
if ( | ||||
if ( $this->is_options_menu() ) { | ||||
$this->rest_preloader->add_preloaded_path( '/amp/v1/unreviewed-validation-counts' ); | ||||
} | ||||
} | ||||
|
||||
/** | ||||
* Whether the current screen is pages inside the AMP Options menu. | ||||
*/ | ||||
public function is_options_menu() { | ||||
thelovekesh marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
return ( | ||||
AMP_Options_Manager::OPTION_NAME === get_admin_page_parent() | ||||
|| | ||||
AMP_Validated_URL_Post_Type::POST_TYPE_SLUG === get_current_screen()->post_type | ||||
) { | ||||
$this->rest_preloader->add_preloaded_path( '/amp/v1/unreviewed-validation-counts' ); | ||||
} | ||||
); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can be on all screens when we core is shipping the expected version of React, but otherwise it can be limited to only the AMP settings pages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, good point. Nevertheless, we will need to not register the polyfills for this since the polyfills are unconditional now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is, unless we limit the service to only run on our dedicated screens. But probably simpler to just remove the polyfill registration entirely for this. Since the service is already conditional based on whether it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we can remove polyfills for it entirely as it's conditional based on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the |
||||
} | ||||
} |
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.
Aside: This is essentially re-making the
Polyfills
service conditional which was removed in #7421Interestingly, also, there are some cases where this will never be reachable:
amp-wp/includes/admin/functions.php
Lines 18 to 54 in 3c17ea9
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.
But only for customizers right?
Actually, added it as a safeguard. Should we remove it? What if it surpassed the condition in any case?
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.
I'm unsure. Maybe what we should do is just change
amp_init_customizer
to justreturn
early if! Services::get( 'dependency_support' )->has_support()
.And then at the same time, we can remove all of the
amp_register_polyfills
actions from this class. What this means is that the custom AMP Customizer integrations won't be available on WP<5.6, but that's effectively the earliest version we support anyway.Additionally, Customizer usage is declining.
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.
So this means replacing all of the contents of this
if
condition:amp-wp/includes/admin/functions.php
Lines 20 to 51 in 3c17ea9
With just
return
.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.
I think you mean:
We can also remove the
@codeCoverageIgnore
right?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.
Yes, that's right.
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.
Or rather, you can make it: