-
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
Block registration: offer option to register a block only in a specific editor #46900
Comments
Going to tag in some folks who I think might have some interesting thoughts/ideas cc @ryanwelcher @adamziel @dmsnell |
Thanks @annezazu for the invite. Thought about this over the weekend and here are some of my inadequate responses:
Sharing thoughts given the ask, but I don't have strong feelings here. I think from what I can see my biggest question revolves around the motivation for adding this. That is, if you are looking for critical feedback, I propose asking if it's adding much over directly adding |
Let me see if I can try to clarify things a bit. I would suggest keeping the conversations in 2 places:
I've updated this issue description to add the header you suggest. I cannot do the same for the Trac ticket though; if you have that option, feel free to edit my ticket description! 1. The workaroundThis would be better discussed in the trac ticket imo. We can at times work around the root problem by only enqueuing assets in the right editor.
I've added a comment to the trac ticket with your questions and my answers. 2. The root problemThis is what I think would be worth discussing here In some scenarios (e.g. when relying fully on In those scenarios, when registering a block or a plugin, it would be nice if plugin authors add an option to declare support for the site editor / widget editor / post editor. Core would then enqueue the assets accordingly. |
@jeherve, thank you for starting the conversation. I added this issue as an item in Block API: Tracking issue. If we had this mechanism in place, we could take advantage of it for some of the core blocks like:
It might be not trivial to cover all those use case, but the developer experience would be excellent when you could just list supported editors as proposed. |
I also wanted to note that this issue is related to #41062, which proposes allowing/denying block use based on post-type or template context. In some cases, providing a post type would be equivalent to limiting access to the post editor, and providing a template would be equivalent to limiting access to the site/template editor. |
Sharing a very relevant comment from @dinhtungdu left under #41062 that was closed as duplicate:
|
This issue is part 2 of a larger discussion spanning multiple issues, about the potential issues plugin authors may face when developing blocks that rely on the
@wordpress/editor
dependency.What problem does this address?
Part of #41236.
Today, when enqueuing assets for a block registered in a plugin, one can rely on
block.json
or hook into theenqueue_block_editor_assets
hook to enqueue necessary scripts and styles in the block editor.This works well, but offers some challenges with some specific blocks. For instance, your block may rely on the
@wordpress/editor
dependency to handle some of its functionality. That dependency is available in the post editor, but cannot be used in the widget editor or the site editor.See #53569-trac and #33203 for more information on this topic.
In this situation, the block you registered ends up enqueuing the
wp-editor
dependency everywhere, thus triggering the warnings added in #53569-core, even though you may not have intended for that block to be available in the site editor or widget editor. It may not even be a block, it could be a plugin you've registered withregisterPlugin
, that you meant to only appear in one of the publish panels.What is your proposed solution?
I've recently opened #57421-trac to offer a way to conditionally enqueue scripts when using
enqueue_block_editor_assets
. I think that can help, but I think it only brings up half way there.Ideally, when registering a block or a plugin, I would want to declare support for the site editor / widget editor / post editor, or exclude my block / plugin from specific editors so its JavaScript (and its dependencies) would automatically never be enqueued there.
What do you think of the idea? Is there a way to do that today that I'm missing?
The text was updated successfully, but these errors were encountered: