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

Docs: Fundamentals of Block Development - Registration of a block #56334

Merged

Conversation

juanmaguitar
Copy link
Contributor

@juanmaguitar juanmaguitar commented Nov 20, 2023

Surfaces documentation for registering a block
This PR closes the issue #55943

This PR proposes surfacing the info about how to register a block to an earlier step in the learning journey (Getting Started > Fundamentals of Block Development > Registration of a block). In order to do this, in this PR the info about how to register a block has been moved from Reference Guides > Block API > Metadata in block.json > Registration of a block to this new page that is part of a new section aimed to improve the onboarding of Block developers

The merge of this PR should also trigger the following redirections:

cc: @gziolo

@juanmaguitar juanmaguitar added the [Type] Developer Documentation Documentation for developers label Nov 20, 2023
@juanmaguitar juanmaguitar changed the title Fundamentals block development/registration of a block Docs: Fundamentals block development - Registration of a block Nov 20, 2023
@juanmaguitar juanmaguitar changed the title Docs: Fundamentals block development - Registration of a block Docs: Fundamentals of Block development - Registration of a block Nov 20, 2023
@juanmaguitar juanmaguitar changed the title Docs: Fundamentals of Block development - Registration of a block Docs: Fundamentals of Block Development - Registration of a block Nov 20, 2023
@juanmaguitar juanmaguitar requested a review from gziolo November 21, 2023 08:36
Copy link

Flaky tests detected in e436065.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6943045213
📝 Reported issues:

@juanmaguitar juanmaguitar added the Developer Experience Ideas about improving block and theme developer experience label Nov 22, 2023

A block is usually registered through a plugin in both the server and the client using its `block.json` metadata.

Although technically, blocks could be registered only on the client, **registering blocks in both the server and the client is a general recommendation**, as some features like Dynamic Rendering, Block Hooks, or Block style variations won't work properly without a server registration of the block.
Copy link
Member

@gziolo gziolo Nov 24, 2023

Choose a reason for hiding this comment

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

I would say that the one very important aspect is missing - it's the entire Style Engine. @oandregal, what would be the way to describe it so it's obvious that registration on the server for block supports is essential for CSS styles to be generated for blocks?

Copy link
Member

Choose a reason for hiding this comment

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

I haven't reviewed everything, but the existing text sounds about right.

I don't know how deep you want to go into this, or if you rather link to existing documents. What I could add is that "global styles" (styles generated from theme.json) require blocks to be registered in the server – otherwise, it's like they don't exist, and any styles assigned to them in theme.json will be ignored. This only matters if the block aims to be styled via theme.json, of course.

I presume the same would be true for all features that generate styles in the server (block supports, layout, style engine, etc.). @aaronrobertshaw @ramonjd @andrewserong @tellthemachines have implemented most of it. They know more than I do on this topic!

Copy link
Member

@gziolo gziolo Nov 24, 2023

Choose a reason for hiding this comment

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

Excellent feedback André. Much appreciate inviting other implementers to share more context 🙇🏻

Copy link
Contributor Author

@juanmaguitar juanmaguitar Nov 24, 2023

Choose a reason for hiding this comment

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

Thanks @gziolo @oandregal for the feedback!
I've updated the PR taking this feedback into account.
Let me know your thoughts.

I don't know how deep you want to go into this, or if you rather link to existing documents.

The purpose of this "Getting Started > Fundamentals of Block Development" is to introduce key ideas to help developers have a better "onboarding" experience for block development. Links to other parts of the Handbook will be used for more details, but in some specific cases, the content will be directly "moved" to this section.

Copy link
Member

@ramonjd ramonjd Nov 26, 2023

Choose a reason for hiding this comment

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

Hi folks, thanks for the ping, and great work on the docs.

In relation to the style engine, along with the general README/usage docs there is some block-supports-specific documentation written here:

https://github.com/WordPress/gutenberg/blob/trunk/packages/style-engine/docs/using-the-style-engine-with-block-supports.md

And there's the handbook entry for block supports.

As @juanmaguitar suggests, maybe it's enough to refer and link to the relevant docs as appropriate should folks wish to enable block supports features to their newly-registered block?

P.S., Going over this stuff made me realize I need to update the style engine block supports docs so I have a PR to do that 😆 So thank you!

Copy link
Member

@ramonjd ramonjd left a comment

Choose a reason for hiding this comment

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

I left mostly very pedantic suggestions :) Thanks!

…on-of-a-block.md

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>
juanmaguitar and others added 5 commits November 26, 2023 10:59
…on-of-a-block.md

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>
…on-of-a-block.md

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>
…on-of-a-block.md

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>
…on-of-a-block.md

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>
…on-of-a-block.md

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>
@juanmaguitar
Copy link
Contributor Author

I left mostly very pedantic suggestions :) Thanks!

@ramonjd Thanks a lot for your suggestions. 🙏
I think they made the texts better. I have accepted them.

@juanmaguitar juanmaguitar requested a review from ramonjd November 26, 2023 10:01
@gziolo
Copy link
Member

gziolo commented Nov 27, 2023

There are some JS unit test failures, but they seem unrelated. It might help to rebase with the trunk.

@@ -77,66 +77,6 @@ Development is improved by using a defined schema definition file. Supported edi
"$schema": "https://schemas.wp.org/trunk/block.json"
```

## Block registration
Copy link
Member

Choose a reason for hiding this comment

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

It would be valuable to link the newly created documentation page, so it's clear that block.json still needs to be wired with PHP and can be used in JavaScript if folks needs access to the same properties.

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

Thank you for working on this new page. It's going to be very helpful in explaining the importance of the server-side registration with WordPress.

@@ -61,14 +61,13 @@ Although registering the block also on the server with PHP is still recommended

The function takes two params:

- `$blockNameOrMetadata` (`string`|`Object`) – block type name (supported previously) or the metadata object loaded from the `block.json` file with a bundler (e.g., webpack) or a custom Babel plugin.
- `$blockNameOrMetadata` (`string`|`Object`) – block type name (if previously registered on the server) or the metadata object loaded from the `block.json` file with a bundler (e.g., webpack) or a custom Babel plugin.
Copy link
Member

Choose a reason for hiding this comment

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

The block can be registered only on the client, so I'm not sure whether the rephrased part fits in that case. Otherwise, it's valid.

Copy link
Contributor Author

@juanmaguitar juanmaguitar Nov 27, 2023

Choose a reason for hiding this comment

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

The text in parenthesis (if previously registered on the server) meant to clarify that registering a block in the client only using block type name only works when the block's metadata has been previously registered on the server.

I'm not sure what (supported previously) is referring to.

But I think I can remove this clarification as this is already explained at the beginning of the Registration of the block with JavaScript (client-side) section

When the block is registered on the server, you only need to register the client-side settings on the client using the same block’s name.

@juanmaguitar juanmaguitar merged commit 26033ae into trunk Nov 28, 2023
51 checks passed
@juanmaguitar juanmaguitar deleted the fundamentals-block-development/registration-of-a-block branch November 28, 2023 05:16
@github-actions github-actions bot added this to the Gutenberg 17.2 milestone Nov 28, 2023
derekblank pushed a commit that referenced this pull request Dec 7, 2023
…6334)

* Add block registration documentation

* Update block registration process

* Update block registration in client code

* updated doc

* Update block registration settings

* Grammar check

* Moved Registration of A block to fundamentals of block development

* Added maarkdown extension

* Delete docs/getting-started/fundamentals-block-development/registration-of-a-block

* Removed "key"

* clarification path block.json

* Fix block.json registration path

* server-side features require block server registration

* server-side features require block server registration

* Update docs/getting-started/fundamentals-block-development/registration-of-a-block.md

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>

* Update docs/getting-started/fundamentals-block-development/registration-of-a-block.md

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>

* Update docs/getting-started/fundamentals-block-development/registration-of-a-block.md

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>

* Update docs/getting-started/fundamentals-block-development/registration-of-a-block.md

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>

* Update docs/getting-started/fundamentals-block-development/registration-of-a-block.md

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>

* Update docs/getting-started/fundamentals-block-development/registration-of-a-block.md

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>

* Fix formatting in registration-of-a-block.md

* Added link to new page and some text adjustments

* Update block registration function and build process reference

---------

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Developer Experience Ideas about improving block and theme developer experience [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants