-
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
HTML Block: Force HTML preview in view mode #66440
Conversation
@@ -23,7 +23,7 @@ const DEFAULT_STYLES = ` | |||
|
|||
export default function HTMLEditPreview( { content, isSelected } ) { | |||
const settingStyles = useSelect( | |||
( select ) => select( blockEditorStore ).getSettings().styles | |||
( select ) => select( blockEditorStore ).getSettings().styles || [] |
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.
I'm a bit unsure about this change, but it may cause styles to temporarily become undefined.
I needed to make this change to prevent the following error:
Uncaught TypeError: Cannot read properties of undefined (reading 'filter') at preview.js:34:19
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 can also do something like (settingStyles ?? [] ).filter( ( style ) => style.css )
.
P.S. That useSelect
is missing the empty dependency array.
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.
Fixed by 7bcb7c0
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +33 B (0%) Total Size: 1.81 MB
ℹ️ View Unchanged
|
const isPreviewMode = useSelect( ( select ) => { | ||
return select( blockEditorStore ).getSettings().isPreviewMode; | ||
}, [] ); |
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.
The isPreviewMode
is also available via the private key in the block edit context. However, considering the block library code is probably the most copied code in the repo, using a selector makes more sense.
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.
Left coupe general notes, but the change looks good to me ✅
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.
Changes look good but I'll move the empty array out of the useSelect like suggested.
Thanks for the review! I think I've addressed all of the feedback so I'd like to merge it. |
Flaky tests detected in 7bcb7c0. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11515638670
|
Co-authored-by: t-hamano <[email protected]> Co-authored-by: Mamaduka <[email protected]> Co-authored-by: youknowriad <[email protected]> Co-authored-by: ndiego <[email protected]> Co-authored-by: talldan <[email protected]>
Fixes #47819
What?
This PR forces HTML preview in view mode regardless of what the mode of the HTML block is.
Why?
In view mode we cannot edit blocks, and in addition, view mode should show as much of how the blocks will actually be rendered as possible.
How?
check
getSettings().isPreviewMode
.Testing Instructions
Screenshots or screencast
e8134991572e541cbc2c3767612626a6.mp4