-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Blook Hooks: Validation errors are thrown if you attempt to use blockHooks
in a block with a save function.
#54796
Comments
That's a good point. I would say that for a start, we should allow only dynamic blocks with More broadly, I believe there should be a way of saying - <p class="outermost-copyright-date-block">© 2017-2023</p> When someone opens the editor in 2024, then the <p class="outermost-copyright-date-block">© 2017-2024</p> This is enough to trigger the block invalid warning. I hope that we can improve handling for dynamic data like the current year with #54536. |
Interesting, that's a pattern that hadn't occurred to me 🤔
The other examples of having both a The problem you're encountering is indeed somewhat inherent in how Block Hooks work: As @gziolo said, since we want them to function on the frontend even if the user never loads and saves them in the editor, they have to be dynamic, and have to render the desired output from their default state, i.e. with no attributes set or inner blocks present. However, since This kind of block validation happens at a fairly low level, so I'm leaning towards disallowing blocks like that from being used as hooked blocks. Note that we might be able to widen the set of allowed blocks a bit beyond "only has a |
@ndiego @ockham @gziolo This seems to be more discussion on what's possible and what's not rather than about something that can be fixed. It's more about defining the boundaries. It made it on to the project board for WordPress 6.4 release, though. What's are your thoughts about taking it off the board? |
Sounds fine to me 👍 (@ndiego feel free to veto/overrule 😄 ) |
Sounds good |
AFAICT, this is no longer a limitation in WP 6.5 (see e.g. the Copyright Date block being used in this example in the Dev Blog post on Block Hooks). |
Description
I was testing the new Block Hooks feature with a custom block I created that has a render function as well as a save function (i.e. neither dynamic nor static).
I applied the following to the block.json file, and the book hook technically works as expected.
However, in the Editor, a block validation occurs due to the save function. See screenshots below.
It might be good to handle these errors more gracefully, or perhaps prevent blocks with a save function from working altogether?
Step-by-step reproduction instructions
block.json
file.Screenshots, screen recording, code snippet
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
No
The text was updated successfully, but these errors were encountered: