fixes #21018 : block preview throws error / fails #21048
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes #21018 - Block preview fails in Gutenberg for all block types containing just text like
For the same reason block styles for core/paragraph and core/heading will not get rendered in the Sidebar inspector panel.
The main reason is that in function
ScaledBlockPreview
(packages/block-editor/src/components/block-preview/scaled.js
) previewElement is expected to be a Element (having methodgetBoundingClientRect
) but the called methodgetBlockPreviewContainerDOMNode(block.clientId)
will return a Text Node instead of an Element for 'core/paragraph' and 'core/heading'. And Text Node does'nt provide method 'getBoundingClientRect'.Screenshots
How has this been tested?
The change ensures that the returned node is a DOM element node (not a DOM text node or anything else ...) having method getBoundingClientRect.
Since the changed function
getBlockPreviewContainerDOMNode
is only used once within a single source file (ScaledBlockPreview.js) its a side effect free change