Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 11 additions & 6 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ import {
registerBlockType,
store as blocksStore,
} from '@wordpress/blocks';
import { useDisabled } from '@wordpress/compose';
import { select } from '@wordpress/data';
import { useBlockProps } from '@wordpress/block-editor';
import { useServerSideRender } from '@wordpress/server-side-render';
import { __, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import HtmlRenderer from './utils/html-renderer';

/**
* Internal dependencies
*/
Expand Down Expand Up @@ -351,7 +357,8 @@ export const registerCoreBlocks = (
apiVersion: 3,
} ),
edit: function Edit( { attributes } ) {
const blockProps = useBlockProps();
const disabledRef = useDisabled();
const blockProps = useBlockProps( { ref: disabledRef } );
const { content, status, error } = useServerSideRender( {
block: blockName,
attributes,
Expand All @@ -376,11 +383,9 @@ export const registerCoreBlocks = (
}

return (
<div
{ ...blockProps }
dangerouslySetInnerHTML={ {
__html: content || '',
} }
<HtmlRenderer
wrapperProps={ blockProps }
html={ content }
/>
);
},
Expand Down
5 changes: 5 additions & 0 deletions packages/block-library/src/utils/html-renderer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* External dependencies
*/
import clsx from 'clsx';
import parse, { attributesToProps, domToReact } from 'html-react-parser';

/**
Expand All @@ -26,6 +27,10 @@ const HtmlRenderer = ( { wrapperProps = {}, html = '' } ) => {
const mergedProps = {
...parsedProps,
...wrapperProps,
className: clsx(
parsedProps.className,
wrapperProps.className
),
Comment on lines +30 to +33
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice catch!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if this needs to be done more automatically for all the props and not just className. think "style" for instance.

};
return (
<TagName { ...mergedProps }>
Expand Down
Loading