Update polyfills service to load unconditionally - #7421
Conversation
âĶ17 compatibility This is required as latest block editor will use React 18
|
Plugin builds for 8d3fb24 are ready ðïļ!
|
|
@thelovekesh Can you check with the latest Gutenberg (v14.8, which includes React 18) if the site scanning that happens after activating a theme/plugin works properly? Since this functionality is not on a dedicated screen, we can't polyfill in that case. If it doesn't work, we may need to adjust the amp-wp/src/Admin/AfterActivationSiteScan.php Lines 84 to 114 in dfb5402 |
|
Yeah, I just checked with Gutenberg 15.1 and on the plugin screen the scan works but I get console warnings: (The second warning about It says that it will behave as if React 17 is active, but I wonder if the upgrade to React 19 will remove that back-compat layer. I see we have two options:
I think we should do the latter for now. |
|
In other words: diff --git a/src/Admin/AfterActivationSiteScan.php b/src/Admin/AfterActivationSiteScan.php
index 1425505c1..ecfc4c1ae 100644
--- a/src/Admin/AfterActivationSiteScan.php
+++ b/src/Admin/AfterActivationSiteScan.php
@@ -11,6 +11,7 @@
namespace AmpProject\AmpWP\Admin;
+use _WP_Dependency;
use AMP_Options_Manager;
use AMP_Validation_Manager;
use AmpProject\AmpWP\Infrastructure\Conditional;
@@ -84,6 +85,8 @@ public function __construct( RESTPreloader $rest_preloader ) {
public static function is_needed() {
global $pagenow;
+ $react = wp_scripts()->query( 'react' );
+
return (
is_admin()
&&
@@ -91,6 +94,8 @@ public static function is_needed() {
&&
! is_network_admin()
&&
+ ( $react instanceof _WP_Dependency && version_compare( $react->ver, '18', '<' ) )
+ &&
AMP_Validation_Manager::has_cap()
&&
( |
* Now AfterActivationSiteScan service will only work on themes.php or plugins.php if React version is less than 18
westonruter
left a comment
There was a problem hiding this comment.
It looks like the E2E tests need updating to account for this condition.
d1fb163 to
079ed38
Compare
|
@westonruter Now using Gutenberg plugin |
3b581fa to
8d3fb24
Compare
| * @return bool Whether the conditional object is needed. | ||
| */ | ||
| public static function is_needed() { | ||
| return ! Services::get( 'dependency_support' )->has_support(); |
There was a problem hiding this comment.
Re: #7458, I just realized an alternative approach to this which could solve some headaches we've encountered: we could restore this and add the conditions for when the polyfills should be registered. Namely, on the various admin screens. Perhaps that is actually not better since then we'd have to maintain the list of screens here, whereas if we go the other (current) approach we only do the polyfills which the respective service fires the amp_register_polyfills action. We just need to make sure that the amp_register_polyfills action only ever fires on our dedicated screens.
So yeah, nevermind.
There was a problem hiding this comment.
With this conditional amp_register_polyfills will only get fired on the AMP plugin screens:
amp-wp/src/Admin/ValidationCounts.php
Lines 132 to 142 in a931e7a





Summary
Polyfillsservice to load unconditionally on required pages where we might need polyfills to keep React 17 compatibility.AfterActivationSiteScanconditional to avoid running site scan on themes and plugins page if React version is>18.Checklist