-
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
Fix server rendered widget not previewing #29197
Conversation
Size Change: +985 B (0%) Total Size: 1.38 MB
ℹ️ View Unchanged
|
@@ -60,12 +61,16 @@ export class ServerSideRender extends Component { | |||
urlQueryArgs = {}, | |||
} = props; | |||
|
|||
const sanitizedAttributes = | |||
attributes && | |||
__experimentalSanitizeBlockAttributes( block, attributes ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just thinking out loud: An alternative could be to use createBlock
here. That way we wouldn't need to add any extra public functions to @wordpress/blocks
.
const sanitizedAttributes = createBlock( block, attributes ).attributes;
But I suppose it makes sense for @wordpress/blocks
to have sanitizeBlockAttributes
as it might be useful in other situations? What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clever! But I fear that it's semantically incorrect? In the future, we could add more logics to the createBlock
factory than sanitizeBlockAttributes
only, that would be hard to catch any unexpected side-effects here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kevin940726!
Description
Originally raised in #29111 (comment).
The problem is that the endpoint
<ServerSideRender>
is using will try to validate theattributes
. Since we're passing__internalWidgetId
now (#29111) to every blocks in the widgets screen, this breaks on the server side.The solution is to sanitize the attributes before sending them to the server. It should be backward-compatible if the client and the server are using the same logic to sanitize/validate the attributes. This PR leverages the
sanitizeBlockAttributes
API to achieve this, not sure if we should mark it as experimental at this stage though.How has this been tested?
Screenshots
Types of changes
Bug fix
Checklist: