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

Fix fatal error by checking if block_type asset properties are set #46488

Merged
merged 7 commits into from
Dec 14, 2022

Conversation

noahtallen
Copy link
Member

@noahtallen noahtallen commented Dec 13, 2022

What?

We've noticed the following fatal error with Gutenberg 14.71, which would be great to resolve in a patch release quickly! Please merge this while I'm offline and create a path release if it looks like a reasonable approach! Or if you have a better idea, overwrite this branch or make a new PR with it! Since it's a fatal error, it'd be nice to not get blocked on async reviews ;)

[10-Dec-2022 12:41:38 UTC] PHP Fatal error:  Uncaught TypeError: array_merge(): Argument #2 must be of type array, null given in /wordpress/plugins/gutenberg/14.7.1/lib/compat/wordpress-6.2/script-loader.php:96
Stack trace:
#0 /wordpress/plugins/gutenberg/14.7.1/lib/compat/wordpress-6.2/script-loader.php(96): array_merge(Array, NULL, NULL)
#1 /wordpress/plugins/gutenberg/14.7.1/lib/compat/wordpress-6.2/script-loader.php(138): gutenberg_resolve_assets_override()
#2 /wordpress/core/6.0.3/wp-includes/class-wp-hook.php(309): {closure}(Array)
#3 /wordpress/core/6.0.3/wp-includes/plugin.php(191): WP_Hook->apply_filters(Array, Array)
#4 /wordpress/core/6.0.3/wp-includes/block-editor.php(507): apply_filters('block_editor_se...', Array, Object(WP_Block_Editor_Context))
#5 /wordpress/core/6.0.3/wp-admin/edit-form-blocks.php(282): get_block_editor_settings(Array, Object(WP_Block_Editor_Context))
#6 /wordpress/core/6.0.3/wp-admin/post.php(187): require('/wordpress/core...')
#7 {main}
  thrown in /wordpress/plugins/gutenberg/14.7.1/lib/compat/wordpress-6.2/script-loader.php on line 96

This adds some safeguards in case these values are not defined or null (isset). Since these new asset properties were introduced in 6.1, they won't work in 6.0.

Question: why is the 6.2 compat lib loaded for WordPress 6.0??

This was answered for me: 6.2 compat lib is loaded to provide compatibility with 6.2 Gutenberg features to older WordPress versions.

Why?

To fix the fatal.

How?

Check if properties isset, and use an empty array if not.

Testing Instructions

Set your .wp-env.override.json file to this to get PHP 8 and WP 6.0

{
	"core": "https://wordpress.org/wordpress-6.0.zip",
	"phpVersion": "8.0"
}

Checkout the current Gutenberg release locally: git checkout tags/v14.7.1.

If you build the Gutenberg plugin and start wp-env, the page will crash trying to edit a post. If you apply the change in this PR, you should be able to edit the post.

Testing Instructions for Keyboard

Screenshots or screencast

demo of fix:

Screen.Recording.2022-12-13.at.1.29.33.PM.mov

@noahtallen noahtallen changed the title Check for NULL value in block_type asset handles Check for null value in block_type asset handles Dec 13, 2022
@noahtallen noahtallen requested review from a team, noisysocks and fluiddot and removed request for a team December 13, 2022 02:43
@noahtallen noahtallen self-assigned this Dec 13, 2022
@noahtallen noahtallen added the [Type] Bug An existing feature does not function as intended label Dec 13, 2022
@noahtallen noahtallen changed the title Check for null value in block_type asset handles Fix fatal error by checking for null in block_type asset handles Dec 13, 2022
@youknowriad
Copy link
Contributor

@noahtallen Were you able to identify the commit or PR that introduced these properties initially? We might want to ask the author to provide compatibility with 6.0 for it.

@noahtallen
Copy link
Member Author

@youknowriad I think it was added in #44298, which @ellatrix worked on (and I think you collaborated on)

We may try to release a patch fix here in the meantime so that we can resolve the fatal error

@noahtallen noahtallen changed the title Fix fatal error by checking for null in block_type asset handles Fix fatal error by checking if block_type asset properties are set Dec 13, 2022
@noahtallen noahtallen force-pushed the null-err-in-script-loader branch from 83d8114 to 789039a Compare December 13, 2022 22:41
Copy link
Member

@fullofcaffeine fullofcaffeine left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏻

@noahtallen noahtallen merged commit e60ecec into trunk Dec 14, 2022
@noahtallen noahtallen deleted the null-err-in-script-loader branch December 14, 2022 02:04
@noahtallen
Copy link
Member Author

Apologies for polluting trunk with multiple commits -- I thought that it would squash merge :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants