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

Spacing-Visualizer: Handle undefined blockElement #69152

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

epeicher
Copy link

@epeicher epeicher commented Feb 11, 2025

What?

Closes Automattic/jetpack#39417

When creating the core/video block transformed from another block, e.g. videopress/video, the blockElement could not be created yet, so it is undefined. This code prevents an error, handing the undefined scenario.

Why?

There is an error when transforming from the VideoPress block to the video block and the error block is displayed with the message:

This block has encountered an error and cannot be previewed.

And the corresponding Javascript error in the console:

spacing-visualizer.js:84 Uncaught TypeError: Cannot read properties of undefined (reading 'ownerDocument')
    at getComputedCSS (spacing-visualizer.js:84:17)
    at computeStyle (spacing-visualizer.js:95:17)
    at spacing-visualizer.js:31:10
    at updateReducer (react-dom.js?ver=18:15855:24)
    at Object.useReducer (react-dom.js?ver=18:17089:18)
    at useReducer (react.js?ver=18:1616:23)
    at SpacingVisualizer (spacing-visualizer.js:21:43)
    at renderWithHooks (react-dom.js?ver=18:15496:20)
    at updateFunctionComponent (react-dom.js?ver=18:19627:22)
    at beginWork (react-dom.js?ver=18:21650:18)

How?

The code returns the passed state in the useReducer when the blockElement is undefined, keeping the previous state.

Testing Instructions

  1. In a Jetpack connected site
  2. Install VideoPress plugin
  3. Add a post and add a video using the VideoPress block
  4. Transform the VideoPress block to a core video block
  5. An error message block is displayed

Testing Instructions for Keyboard

Screenshots or screencast

Before video

Kapture.2024-09-17.at.10.24.41.mp4

After video

CleanShot.2025-02-14.at.19.45.39.mp4
Before After

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Feb 11, 2025
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @epeicher! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Block] Video Affects the Video Block labels Feb 14, 2025
@epeicher epeicher marked this pull request as ready for review February 14, 2025 18:48
Copy link

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: epeicher <[email protected]>
Co-authored-by: mrfoxtalbot <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Video Affects the Video Block First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Converting a VideoPress block to regular video causes the block to crash
2 participants