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

register_block_type's editor_script handle fails if it is an array. #44687

Closed
nendeb opened this issue Oct 4, 2022 · 5 comments
Closed

register_block_type's editor_script handle fails if it is an array. #44687

nendeb opened this issue Oct 4, 2022 · 5 comments
Labels
Backwards Compatibility Issues or PRs that impact backwards compatability Needs Testing Needs further testing to be confirmed.

Comments

@nendeb
Copy link

nendeb commented Oct 4, 2022

Description

When creating a custom block, I was giving editor_script multiple handles and passing them as an array.
This works fine in WP6.0, but fails in WP61, making the block unusable.

I know that editor_script was deprecated in WP6.1 and replaced with editor_script_handles, but it is not backward compatible that editor_script cannot be passed as an array, so please fix this.

Step-by-step reproduction instructions

In the following sample Works on wp6.0 and fails on wp61.

	register_block_type(
		'exsample/exsample-custom-block',
		array(
			'apiVersion' => 2,
			'editor_script' => array(
				'handle1-js',
				'handle2-js',
				'handle3-js',
			),

Screenshots, screen recording, code snippet

No response

Environment info

WordPress 6.1-beta3
Gutenberg 14.2

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@talldan talldan added Backwards Compatibility Issues or PRs that impact backwards compatability Needs Testing Needs further testing to be confirmed. labels Oct 5, 2022
@thelovekesh
Copy link
Member

What's the use case of passing multiple scripts here? IMO these files should be concatenated in one using some bundler like webpack, hence no such case will arise.

You can check @wordpress/scripts package for such tasks.

@Soean
Copy link
Member

Soean commented Oct 5, 2022

In WordPress 6.0, the editor_scriptin register_block_type only accepts a string: https://developer.wordpress.org/reference/functions/register_block_type/.
I don't see an backward compatible issue here.

@nendeb
Copy link
Author

nendeb commented Oct 5, 2022

What I want to load is not only the built index.js, but also the javascript that I want to run after the custom block is displayed.
For example, a slider.

The purpose is to load javascript only when the block is available.

If you set up an arrayed handles in editor_script.
WP6.0 throws the handles as that array to wp_enqueue_style.
This works fine, but it is strange.

WP6.0 throws an array of editor_script handles at wp_enqueue_style.
This is working but strange.

@ockham
Copy link
Contributor

ockham commented Oct 18, 2022

Noting that @nendeb has filed a Core ticket which has had some more discussion and a tentative fix: https://core.trac.wordpress.org/ticket/56707.

@ockham
Copy link
Contributor

ockham commented Oct 24, 2022

This has now been fixed in Core in r54670 and backported to the 6.1 branch in r54671.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backwards Compatibility Issues or PRs that impact backwards compatability Needs Testing Needs further testing to be confirmed.
5 participants