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

Always provide polyfill for dependencies if WP or Gutenberg plugin is not supported; ensure onboarding wizard works on < WP 5.6 #6225

Merged
merged 39 commits into from
May 18, 2021

Conversation

pierlon
Copy link
Contributor

@pierlon pierlon commented May 12, 2021

Summary

Fixes #6194.

This PR ensures that the polyfilled dependencies are always registered if WP or the active Gutenberg plugin is known to have outdated dependencies, which can sometimes cause some plugin screens to not work as intended.

Also, polyfills are now provided for the onboarding wizard so that it is operable on WP < 5.6.

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).

@pierlon pierlon added this to the v2.1.2 milestone May 12, 2021
@github-actions
Copy link
Contributor

github-actions bot commented May 12, 2021

Plugin builds for 303a4a3 are ready 🛎️!

@pierlon pierlon requested a review from westonruter May 12, 2021 20:41
@pierlon pierlon changed the title Ensure polyfill dependencies are registered if WP or Gutenberg version is not supported Ensure polyfilled dependencies are registered if WP or Gutenberg version is not supported May 12, 2021
@westonruter westonruter requested a review from delawski May 13, 2021 01:18
includes/admin/functions.php Outdated Show resolved Hide resolved
src/DependencySupport.php Outdated Show resolved Hide resolved
src/DependencySupport.php Show resolved Hide resolved
Comment on lines -525 to +526
if ( version_compare( get_bloginfo( 'version' ), '4.9', '<' ) ) {
$this->markTestSkipped( 'The WP version is less than 4.9, so Gutenberg did not init.' );
if ( version_compare( get_bloginfo( 'version' ), '5.0', '<' ) ) {
$this->markTestSkipped( 'Gutenberg for WP < 5.0 is not supported.' );
Copy link
Member

Choose a reason for hiding this comment

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

Is this change and the latter correct since in WP 4.9 the 4.9.0 version of Gutenberg is installed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I meant 'not supported' in the sense that the do_blocks hook occurs at priority 7 instead of 9 in GB 4.9.0, so the functionality being tested here would fail.

@westonruter
Copy link
Member

Todo: Onboarding Wizard should work on WP<5.6 if the AMP Settings screen is also supposed to work.

@pierlon pierlon requested a review from westonruter May 14, 2021 03:35
@pierlon
Copy link
Contributor Author

pierlon commented May 14, 2021

Todo: Onboarding Wizard should work on WP<5.6 if the AMP Settings screen is also supposed to work.

Done in f0962b1. The onboarding wizard should be operable as far back as WP 4.9.

@pierlon pierlon changed the title Ensure polyfilled dependencies are registered if WP or Gutenberg version is not supported Always provide polyfill for dependencies if WP or Gutenberg plugin is not supported; ensure onboarding wizard works on < WP 5.6 May 14, 2021
Copy link
Collaborator

@delawski delawski left a comment

Choose a reason for hiding this comment

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

The code, specifically the JS/Gutenberg-related part, looks good to me.

I've tested out the update on WordPress 4.9.8 with Gutenberg 4.9.0 activated and can confirm that both the Settings page and the Wizard work well now.

@@ -160,7 +160,7 @@ const customizer = {

const WORDPRESS_NAMESPACE = '@wordpress/';
const BABEL_NAMESPACE = '@babel/';
const gutenbergPackages = [ '@babel/polyfill', '@wordpress/dom-ready', '@wordpress/i18n', '@wordpress/hooks', '@wordpress/url' ].map(
const gutenbergPackages = [ '@babel/polyfill', '@wordpress/dom-ready', '@wordpress/i18n', '@wordpress/hooks', '@wordpress/html-entities', '@wordpress/url' ].map(
Copy link
Member

Choose a reason for hiding this comment

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

@pierlon The @wordpress/html-entities is a new dependency that we use which needs to be polyfilled or else an error occurs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's needed for the onboarding wizard to load in WP 4.9.

@pierlon
Copy link
Contributor Author

pierlon commented May 17, 2021

@westonruter can you confirm if 98e259c fixes the AMP Enabled link in the classic editor?

@westonruter
Copy link
Member

can you confirm if 98e259c fixes the AMP Enabled link in the classic editor?

@pierlon I can see the notice in the 4.9.0 block editor, but the AMP toggle in 4.9 when Gutenberg is deactivated is still inert:

edit-link-not-working.mov

@westonruter
Copy link
Member

I think we should replace that line with a notice to ask the user to upgrade.

@westonruter
Copy link
Member

With d2b79c1, users of unsupported versions of WordPress will see:

image

@westonruter
Copy link
Member

On the Settings screen, the user sees the notice repurposed from what was originally in the Welcome component:

image

@@ -163,6 +163,11 @@ public function enqueue_admin_assets() {

wp_styles()->add_data( self::ASSETS_HANDLE, 'rtl', 'replace' );

// Abort if version of WordPress is too old.
if ( ! Services::get( 'dependency_support' )->has_support_from_core() ) {
Copy link
Member

Choose a reason for hiding this comment

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

I chose to go with checking for core support here rather than support in general because I figure it would be a bad idea to try to amp_register_polyfills on the edit post screen, not knowing what possible conflicts could result.

Co-authored-by: Weston Ruter <[email protected]>
Comment on lines 154 to 163
'my-gb-post-type',
[
'public' => true,
'show_in_rest' => true,
'supports' => [ 'editor' ],
]
);

set_current_screen( 'edit.php' );
$post = $this->factory()->post->create( [ 'post_type' => 'my-gutenberg-post-type' ] );
Copy link
Member

Choose a reason for hiding this comment

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

This test is failing, at least because my-gb-post-type is the post type defined but my-gutenberg-post-type is the post type created, but neither of these are among the AMP_Post_Type_Support::get_eligible_post_types().

@westonruter
Copy link
Member

Fixing test…

@westonruter
Copy link
Member

westonruter commented May 18, 2021

See test cases in the description on #6194.

@westonruter westonruter merged commit d321a76 into develop May 18, 2021
@westonruter westonruter deleted the fix/wp-4.9-settings-screen-with-gutenberg-active branch May 18, 2021 01:45
westonruter added a commit that referenced this pull request May 18, 2021
… not supported; ensure onboarding wizard works on < WP 5.6 (#6225)

Co-authored-by: Pierre Gordon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WP 4.9 + Gutenberg: Uncaught TypeError: Object(...) is not a function on settings page
3 participants