I understand my question may be a bit broad, or even easy to answer. I have been building custom blocks using the --es5
flag of @wordpress/create-block
(https://developer.wordpress.org/block-editor/packages/packages-create-block/), which has been fairly successful on projects.
The reason for using this method is that during development and post-launch there are often many changes required of the block and from my past experience (over a year ago) the ES Next method effectively 'killed' the block as soon as a change was made. So you would have to go through every instance of this block and change it.
Have WP's developers come up with a workable solution for this which enables developers to use the ES Next method in a project safely? I'd prefer to be using the methods as intended. The documentation since it's release has not been great so I thought it would be better to ask the wider community.
To try and explain better what I mean:
Building a custom block using the following method (https://github.com/WordPress/gutenberg-examples/blob/master/03-editable/block.js) of attributes with the --es5 flag appears to be more stable in terms of backwards compatibility. If I were to make changes to the render template (https://github.com/WordPress/gutenberg-examples/blob/master/03-editable/index.php) it wouldn't break the block.
Using the 'React' method (https://github.com/WordPress/gutenberg-examples/blob/master/03-editable-esnext/src/index.js), in my past experience, has caused issues. If I build a custom block using this method and a change has been made to the block's code, it 'kills' the block. There is no backwards compatibility from what I can tell.
I'm wondering if this is just something that has actually been resolved since the block editor was first introduced. Or is the way to continue building custom blocks is using the ES5 method
One important bit I have missed out What I was originally alluding to is that I am using server side rendered blocks (excuse my terminology here, its not exactly a clear subject to those unfamiliar with it) that gets around the 'change anything in the block code and you have to add that block again in the editor' problem. Not Ideal for client handover.
register_block_type( 'create-block/perk', array(
'editor_script' => 'create-block-perk-block-editor',
'editor_style' => 'create-block-perk-block-editor',
'style' => 'create-block-perk-block',
'render_callback' => 'perk_block_render',
) );
function perk_block_render($attr, $content) {
$str = '';
if(isset($attr['mediaID'])) {
$mediaID = $attr['mediaID'];
$src = wp_get_attachment_image_src($mediaID, 'perk');
if($src && is_array($src) && isset($src[0])) {
$srcset = wp_get_attachment_image_srcset($mediaID);
$sizes = wp_get_attachment_image_sizes($mediaID, 'perk');
$alt = get_post_meta($mediaID, '_wp_attachment_image_alt', true);
if(!$alt) {
$alt = 'Perk icon';
}
}
}
if(isset($attr['titleContent'])) {
$title = $attr['titleContent'];
}
if(isset($attr['subContent'])) {
$subtitle = $attr['subContent'];
}
$str = "<div class='perks__item animate'>";
if($mediaID) {
$str .= "<img loading='lazy' width='170' height='170' src='{$src[0]}' alt='{$alt}'/>";
}
if($title) {
$str .= "<h2>{$title}</h2>";
}
if($subtitle) {
$str .= "<p>{$subtitle}</p>";
}
$str .= "</div>";
return $str;
}
I see now that it is not ES5/ESNext related, however, after looking through recent videos it seems like it is still an issue with developing custom blocks using WordPress's 'preferred' method. And also, judging by the answers using server-side-rendered blocks is the only way away this. Is my code going to experience issues if I continue to use server-side rendered blocks?
--es5
flag of what?