Skip to content
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

Fixed Random Collapse of Colors Setting Section #32388

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions packages/block-editor/src/hooks/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,7 @@ export const withBlockControls = createHigherOrderComponent(
const withElementsStyles = createHigherOrderComponent(
( BlockListBlock ) => ( props ) => {
const elements = props.attributes.style?.elements;
if ( ! elements ) {
return <BlockListBlock { ...props } />;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this causes a remount which is not great for BlockEdit components. We had similar issues in other hooks in the past. So yeah the fix here is looking good to me.

}

const blockElementsContainerIdentifier = `wp-elements-${ useInstanceId(
BlockListBlock
) }`;
Expand All @@ -259,17 +257,23 @@ const withElementsStyles = createHigherOrderComponent(

return (
<>
<style
dangerouslySetInnerHTML={ {
__html: styles,
} }
/>
{ elements && (
<style
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside: (something for other PRs) Also noting that inline styles like that (which we do in layout as well), can cause CSS issues due to the new elements breaking :first-child selectors and things like that in editor styles.

@jorgefilipecosta @nosolosw @ellatrix We may need a dedicated way to inject these styles in the editor (and maybe even in the frontend) that doesn't suffer from these issues.

dangerouslySetInnerHTML={ {
__html: styles,
} }
/>
) }

<BlockListBlock
{ ...props }
className={ classnames(
props.classname,
blockElementsContainerIdentifier
) }
className={
elements &&
classnames(
props.classname,
blockElementsContainerIdentifier
)
}
/>
</>
);
Expand Down