-
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
Issue with ServerSideRender with additional props #16850
Comments
I just ran into this problem myself with a plugin I'm building. Anyone know of a way to check for this so that I can not add my custom attributes to blocks that they wouldn't work on? |
In case anyone is facing this issue and wants to patch their plugin, this will be of help: https://github.com/Codeinwp/blocks-css/pull/5/files |
I just came across this one too while working on a dynamic block... |
Also encountered this issue while creating a custom block. |
I came across this error by using This can be avoided by adding the register_block_type( 'mynamespace/myblock', [
'editor_script' => 'mynamespace-myblock',
'editor_style' => 'mynamespace-myblock-editor',
'render_callback' => 'mynamespace-myblock-render',
'attributes' => [
'className' => [
'default' => '',
'type' => 'string'
]
]
] ); Note: Adding |
thanks @neojp that fixed my issue |
Does anyone know if progress has been made on fixing this in Core, or is the patch still the way to go. Ran into this yesterday in WooCommerce on all their blocks using server side rendering. |
Is this still an issue? I'm not sure I understand the problem here? It sounds very related to how the core block supports work and now that all core blocks are registered server side we can just retrieve the block type from the registry and add any attribute we want. |
@youknowriad I am not sure, but I will test this weekend and report back. A couple of my plugins are using the patch outlined above, but that might not be needed anymore. |
Yes, this issue still exists. If you want to add your own custom attributes to any block that uses |
That doesn't seems like a problem to me, since this is a server side rendered block, it does make sense to register the attribute on the server and you can do so by retrieving the registered block on the server and altering its attributes definition. |
@youknowriad yup that makes sense. I might prepare a ticket for the handbook in the next week or so, because I think we should document, or at least note, that the |
Help us move this issue forward. Since it has no activity after 15 days of requesting more information, a bot is marking the issue as stale. Please add additional information as a comment or this issued will be closed in 5 days. |
This issue was closed because more information was requested and there was no activity. If this is a bug report and still a problem, please supply the additional information requested and reopen the issue. |
In Now it makes sense from a certain perspective that if a JS side filter registers a custom attribute for a block, but the server side render function does not declare support for that attribute there is an incompatibility between the server side rendered block and that extension. In an ideal world a proper solution would be either:
The problem is in reality certain editor plugins would add some "global" settings to every block. For example those could be to control selective rendering based on external conditions etc. Such behaviour can work without explicit support from the targeted block, because a plugin can hook into the However by setting the schema definition to use The solution would be to add a filter that a plugin adding custom attributes to all blocks could use to actually enable it's own "additional properties" for server side rendered blocks, even if those blocks would not explicitly support those properties. EDIT: Nevermind. I've figured I can use the |
I'm using Gutenberg's API to add additional attributes to core blocks, in a plugin like these:
Now this works fine with all the blocks but with the ones that use ServerSideRender component. When these additional attributes are passed, the block responds with (sometimes after refreshing the page/editor):
Error loading block: Invalid parameter(s): attributes
I see that I can use
block_attributes
filter to pass these additional props and its data type, but is it the only way around? Or is it a bug with ServerSideRenderer's REST Route?Update: Seems like
block_attributes
filter was removed before 5.0: https://github.com/WordPress/WordPress/blob/bc9dfcfeb1d384e3060ddc25c5755647dbe50985/wp-includes/class-wp-block-type.php#L200So what to do with these additional attributes when a block user server-side renderer? If they don't work it's fine but the block crashes and that's not ideal.
The text was updated successfully, but these errors were encountered: