Leonardo Losoviz
Creator of Gato GraphQL, and contributor to several online magazines, including Smashing Magazine and CSS Tricks.
(The WordPress editor)
🤔
🤔
🤔
Part I:
As of today, WordPress assumes only one role within the stack for building websites: the CMS (currently powering 43% of all sites).
Thanks to the Block Protocol, WordPress could assume a new role in the modern tech stack: providing blocks to power the front-end of any application.
By using the blocks offered by WordPress, developers who do not normally use WordPress may become acquainted with it and become contributors, bringing along a diverse skill set.
Blocks coded for non-WordPress applications would become available to power WordPress sites.
Any implementation engine other than Gutenberg can take its place, providing a different experience that is still powered by the same blocks.
This is valid not only for non-WordPress applications, but also for the public-facing WordPress site. (Currently, blocks are normally used in the wp-admin only, which is where Gutenberg lives.)
There are many uses cases for displaying blocks on the client:
Dynamic blocks currently require some logic to be implemented twice: in JavaScript (for the editor) and PHP (dynamic output in the client).
The Block Protocol would allow avoiding the PHP duplication, by using client-side rendering (CSR) instead of server-side rendering (SSR).
Similar to the experience produced by GraphQL, adhering to a shared protocol could lead to non-coordinated developments within the wider community, potentially producing a rich ecosystem of tooling that Gutenberg can benefit from.
The block's JSON schema would need to provide the ultimate type of `array` and `object` properties (which is encouraged but not made mandatory by Gutenberg).
Clients, tools and other protocols could benefit from this extra information (in particular GraphQL).
In the Block Protocol, the block must be a black box, whose inner workings are hidden from view.
This affects styling. If the application doesn't know what's the inner configuration of a block (what HTML tags, CSS classnames, etc), then it can't reliably apply some intended style to the block.
Developers of generic blocks may be tempted to embed within plenty of extra functionalities, bloating the block.
The application may not use these, but the code will still be transmitted over the Internet, slowing down the load of the webpage and the parsing and the JS code within, and unnecessarily consuming more energy.
Using a block from the Block Hub will make sense as long as there is no equivalent block in the WordPress editor already, or offered by some 3rd party WordPress plugin.
The reason is that generic blocks can never match native blocks in their integration with Gutenberg.
The JSON schema for the Gutenberg block would either require breaking changes, or a conversion tool to make it compatible with the Block Protocol.
In either case, the project becomes more complex, and more difficult to maintain.
Due to the nature of Gutenberg and WordPress, there are features that may particularly make sense within their context, but not in a general context.
{
"attributes": {
"url": {
"type": "string",
"source": "attribute",
"selector": "img",
"attribute": "src"
}
},
"tokenSupport": {
"core/featured-image": {
"selector": "img",
"attribute": "src"
}
}
}
These custom features (such as dynamic tokens) would not be supported by the Block Protocol.
The Block Protocol has been launched before having any fully-functional implementation of a compliant application. (The company that created the protocol is developing an app, but it is still a work in progress.)
As such, there is no example app to guide us on integrating the Block Protocol into Gutenberg.
One of the potential benefits of the Block Protocol is that Gutenberg blocks will be used outside of the WordPress realm. This cannot be supported by existing evidence, since there are no Block Protocol apps yet, and we don't know if the wider community will embrace it or not.
The specification may be subjected to substantial modifications once applications start making use of it.
In addition, several known sections are currently incomplete, and currently-missing sections (such as "configuration") might need to be added.
Part II:
We can expect a non-negligible investment required in terms of development work, to be carried out on a permanent basis.
The WordPress community is already struggling with its own tasks, and adding more will only make the situation more stressful.
WP-CLI maintainer Alain Schlesser expressed that the concept of a generic block is flawed, since it can never satisfy everyone's needs, and as such the Block Protocol will be unable to deliver on its promises.
There are several red flags surrounding the Block Protocol:
😲
(This is my personal opinion)
😢
🤓
Part III:
*It won't generate plug-and-play blocks (like the Block Protocol), but a tradeoff between:
Gutenberg blocks should communicate with the underlying engine via a clearly-defined interface, made to match exactly the Gutenberg API.
Gutenberg will then be a provider of its own interface, and any other engine that implements the same interface can also embed Gutenberg blocks.
Gutenberg blocks need to get their data from somewhere, but they should not care where from.
const EditBlock = ( {
className,
dataSource = 'wp-json/wp/v2/posts',
} ) => {
return (
<div className={ className }>
<MyComponent
restEndpoint={ dataSource }
/>
</div>
);
}
Instead of interacting with predefined WP REST API endpoints, either the actual data, or the data source to use, must be injected into the component via props. The current REST endpoint can be the default value.
A block is a collection of JavaScript components, which might already be re-usable/portable across applications.
We can then forgo making our blocks reusable, and instead provide reusability at the component level (check Storybook).
Our main task becomes moving code, as much as possible, from the block layer into the component layer.
Styling is inadequate in the Block Protocol because it treats the block as a black box.
A simpler solution is to allow the app to peer inside of the block, and request that CSS classnames (with a predefined naming format) be added to each and every HTML tag.
Nahhhhh
👨🏻💻
By Leonardo Losoviz
WordPress creator Matt Mullenweg has expressed interest in joining forces with the Block Protocol, a new specification which aims to have “blocks” be portable across applications. This talk presents the benefits and costs for WordPress if it were to adopt this new protocol, and then, based on this information, it draws conclusions on how desirable it is to happen.
Creator of Gato GraphQL, and contributor to several online magazines, including Smashing Magazine and CSS Tricks.