-
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
Site Editor: Remove extra div on post content #38451
Conversation
<div { ...blockProps }> | ||
<RawHTML key="html">{ content?.rendered }</RawHTML> | ||
</div> | ||
<RawHTML key="html" { ...blockProps }> |
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.
This causes and error in the console because it's trying to set a ref on an functional component which isn't possible.
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.
Can you use dangerouslySetInnerHTML
on the div
instead? RawHTML
is a special wrapper mostly for save
implementation of the block when you don't want any wrapping DOM elements.
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.
Oh yeah, that seems to work. What do you think?
Size Change: +1.19 kB (0%) Total Size: 1.14 MB
ℹ️ View Unchanged
|
I don't think this is the right approach, but I'm not sure how else to solve this one. |
Can we remove When searching |
Thanks for the PR @scruffian! @ellatrix do you think we can |
Thanks for looking into the I also did some testings; it looks like If I run the following snippet in the console I get results with the correct behavior: const element1 = wp.element.createElement( wp.element.RawHTML, { key: 'html' }, '<div>Hello</div>' );
const element2 = wp.element.createElement( wp.element.RawHTML, { className: 'greetings' }, '<div>Hello</div>' );
// Has no wrapper div
console.log( wp.element.renderToString( element1 ) );
// Has wrapper div
console.log( wp.element.renderToString( element2 ) ); |
In my tests removing the key prop didn't make a difference - I think key gets treated differently to other props anyway. I think the issue here might be that the block itself isn't being serialized. |
Removing the key doesn't make any difference in that case because we are passing all the other props from |
I tried the approach @gziolo suggested. Not sure if it breaks anything else! |
<div { ...blockProps }> | ||
<RawHTML key="html">{ content?.rendered }</RawHTML> | ||
</div> | ||
createElement( 'div', { |
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.
You don't need to use createElement
. Just append the dangerouslySetInnerHTML
to the existing div
.
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.
Of course 🤦
Done!
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.
It should be good 👍
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.
Looks like there's a small whitespace change needed to get the linting step passing, but once that's fixed up, this looks good to merge to me, too!
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 @scruffian!
Description
The post content block outputs and additional div when being rendered in the Site Editor. This is coming from the RawHTML component. There is a comment which suggests the extra div should be removed when the block is serialized but that doesn't seem to be happening.
This additional div is causing issues with out alignment styles for themes - see Automattic/themes#5385
Testing Instructions
Checkout this PR: Automattic/themes#5385
Switch to the Livro theme
Open the Site Editor
Confirm that wide and full blocks go to the edge of the editor
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist:
*.native.js
files for terms that need renaming or removal).