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

Unregistering core/site-logo block crashes editor when editing Patterns #63208

Closed
MadtownLems opened this issue Jul 5, 2024 · 7 comments · Fixed by #63252
Closed

Unregistering core/site-logo block crashes editor when editing Patterns #63208

MadtownLems opened this issue Jul 5, 2024 · 7 comments · Fixed by #63252
Assignees
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended [Type] Regression Related to a regression in the latest release

Comments

@MadtownLems
Copy link

Description

When using javascript to unregister the core/site-logo block, and trying to add/edit a Pattern, the editor crashes with the following error: TypeError: Cannot read properties of undefined (reading 'styleVariationSelectors')

Step-by-step reproduction instructions

Enqueue the following javascript:

wp.domReady( () => {

    // does NOT crash editing Patterns; successfully unregisters archives block
    wp.blocks.unregisterBlockType( 'core/archives' );

    // crashes editing Patterns with error:
    // TypeError: Cannot read properties of undefined (reading 'styleVariationSelectors')

	wp.blocks.unregisterBlockType( 'core/site-logo' );
	

} );

Attempt to add or edit a Pattern. The editor crashes and lets you copy the error, which is:
TypeError: Cannot read properties of undefined (reading 'styleVariationSelectors')

Screenshots, screen recording, code snippet

No response

Environment info

WP 6.6-RC-2. (I have confirmed the same behavior on 6.6-RC-1, but I am quite confident that this did not crash on the early Beta I tested, and it definitely doesn't crash on 6.5.5)
No Gutenberg Plugin

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@MadtownLems MadtownLems added the [Type] Bug An existing feature does not function as intended label Jul 5, 2024
@t-hamano
Copy link
Contributor

t-hamano commented Jul 6, 2024

Thanks for the report.

I was able to reproduce this issue too. This issue does not occur in WP6.5. It does occur in WP6.6 RC2 and the latest Gutenberg.

ae49830e0d2bf1951071897345b270b6.mp4

@t-hamano t-hamano added the Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json label Jul 6, 2024
@ndiego
Copy link
Member

ndiego commented Jul 8, 2024

Yup, I can confirm, but this appears to be a larger issue. The Site Editor crashes when registering Image blocks as well and perhaps others. I have not tested all blocks.

wp.domReady( () => {
	// Crashes Site Editor with error:
	// wp.blocks.unregisterBlockType( 'core/site-logo' );
	wp.blocks.unregisterBlockType( 'core/image' );
} );
image

@ndiego ndiego moved this to ❓ Triage in WordPress 6.6 Editor Tasks Jul 8, 2024
@ndiego ndiego added [Type] Regression Related to a regression in the latest release [Feature] Extensibility The ability to extend blocks or the editing experience labels Jul 8, 2024
@ndiego
Copy link
Member

ndiego commented Jul 8, 2024

Flagging you all since this appears to be an extensibility regression: @fabiankaegy @colorful-tones @ellatrix @vcanales

@t-hamano
Copy link
Contributor

t-hamano commented Jul 8, 2024

The following changes seem to fix the critical issue, but may not be ideal. Perhaps @aaronrobertshaw knows more about this part of the code?

diff --git a/packages/block-editor/src/components/global-styles/use-global-styles-output.js b/packages/block-editor/src/components/global-styles/use-global-styles-output.js
index 6756398708..41d6970d03 100644
--- a/packages/block-editor/src/components/global-styles/use-global-styles-output.js
+++ b/packages/block-editor/src/components/global-styles/use-global-styles-output.js
@@ -671,7 +671,7 @@ export const getNodesWithStyles = ( tree, blockSelectors ) => {
                                                }
                                                const variationSelector =
                                                        blockSelectors[ blockName ]
-                                                               .styleVariationSelectors?.[ variationName ];
+                                                               ?.styleVariationSelectors?.[ variationName ];
 
                                                // Process the variation's inner element styles.
                                                // This comes before the inner block styles so the

@ndiego
Copy link
Member

ndiego commented Jul 8, 2024

The following changes seem to fix the critical issue, but may not be ideal.

🤞 this issue is just due to a missing ?.

@aaronrobertshaw
Copy link
Contributor

Thanks for the ping 👍

It does look like I missed the optional chaining operator there, working under the impression the block nodes would match the available blocks.

Given that isn't the case the proposed fix is along the right lines. This issue also shows that a variation's inner blocks could also be deregistered triggering a similar error a few lines down.

I'll put together a fix in a moment.

@aaronrobertshaw
Copy link
Contributor

A fix following Aki's suggestion is available in #63252.

@colorful-tones colorful-tones moved this from ❓ Triage to 🔎 Needs Review in WordPress 6.6 Editor Tasks Jul 8, 2024
@github-project-automation github-project-automation bot moved this from 🔎 Needs Review to ✅ Done in WordPress 6.6 Editor Tasks Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended [Type] Regression Related to a regression in the latest release
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants