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

Post Unrecoverably Crashes If Unregistering an In-Use Core Block #12484

Open
mrwweb opened this issue Nov 30, 2018 · 7 comments
Open

Post Unrecoverably Crashes If Unregistering an In-Use Core Block #12484

mrwweb opened this issue Nov 30, 2018 · 7 comments
Labels
[Feature] Block API API that allows to express the block paradigm. [Type] Bug An existing feature does not function as intended

Comments

@mrwweb
Copy link

mrwweb commented Nov 30, 2018

Describe the bug
If I unregister a core block type has been previously used, the entire post unrecoverably crashes.

To Reproduce

  1. Create a new post
  2. Add the Verse alock
  3. Add code to unregister the verse block (the proper way to do this still isn't documented! see: Clarify Documentation for How to Unregister a Single Block with JS #11723)
  4. Reload the post (See error details)
  5. Disable code to unregister Verse block
  6. Post is fixed

Here's the JS I'm using to disable the Verse Block:

window.onload = function() {
    wp.blocks.unregisterBlockType( 'core/verse' );
};

Error Details
"The editor has encountered an unexpected error." 3 buttons: Attempt Recovery, Copy Post Text, Copy Error

Copy Error results:

value/<@https://myplugins.local/wp-includes/js/dist/editor.min.js?ver=9.0.2:55:115657
value@https://myplugins.local/wp-includes/js/dist/editor.min.js?ver=9.0.2:55:109652
Fd@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:92:365
Mf@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:92:160
ph@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:98:474
eg@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:125:307
fg@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:126:168
wc@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:138:237
gg@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:135:160
Ca@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:133:365
og@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:150:95
Rd@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:150:173
bb.prototype.render@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:200:185
Bc/<@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:153:485
mg@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:148:406
Bc@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:153:420
render@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:202:194
$n@https://myplugins.local/wp-includes/js/dist/edit-post.min.js?ver=3.1.2:12:69103
value@https://myplugins.local/wp-includes/js/dist/editor.min.js?ver=9.0.2:55:271759
Fg@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:154:231
Eg@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:13:419
Hg@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:13:473
ae@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:15:133
Ig@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:155:69
Hc@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:15:416
Jc@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:16:489
gh@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:39:335
lg@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:148:319
re@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:23:322
Xb@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:40:304
ng@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:149:39
Se@https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:40:45

Copy Post Text:

{nothing, doesn't work}

Attempt Recovery:
Nothing happens

Console:

TypeError: "x is undefined"
value https://myplugins.local/wp-includes/js/dist/editor.min.js?ver=9.0.2:55:115657
value https://myplugins.local/wp-includes/js/dist/editor.min.js?ver=9.0.2:55:109652
Fd https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:92:365
Mf https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:92:160
ph https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:98:474
eg https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:125:307
fg https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:126:168
wc https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:138:237
fa https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:137:115
lg https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:148:342
re https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:23:322
Xb https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:40:304
react-dom.min.js:104:245
TypeError: "x is undefined"
value https://myplugins.local/wp-includes/js/dist/editor.min.js?ver=9.0.2:55:115657
value https://myplugins.local/wp-includes/js/dist/editor.min.js?ver=9.0.2:55:109652
Fd https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:92:365
Mf https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:92:160
ph https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:98:474
eg https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:125:307
fg https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:126:168
wc https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:138:237
gg https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:135:160
Ca https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:133:365
og https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:150:95
Rd https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:150:173
render https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:200:185
Bc https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:153:485
mg https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:148:406
Bc https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:153:420
render https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:202:194
n https://myplugins.local/wp-includes/js/dist/edit-post.min.js?ver=3.1.2:12:69103
value https://myplugins.local/wp-includes/js/dist/editor.min.js?ver=9.0.2:55:271759
Fg https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:154:231
Eg https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:13:419
Hg https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:13:473
ae https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:15:133
Ig https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:155:69
Hc https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:15:416
Jc https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:16:489
gh https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:39:335
lg https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:148:319
re https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:23:322
Xb https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:40:304
ng https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:149:39
Se https://myplugins.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.6.3:40:45
react-dom.min.js:104:245

Expected behavior
Post should display the "block doesn't exist" behavior for third-party blocks:

image

Desktop (please complete the following information):
Win 10, Firefox 63.0.3, 5.0-RC1-43947, Twenty Nineteen, Tiny plugin to deactivate Verse Block and a few others

@swissspidy swissspidy added [Type] Bug An existing feature does not function as intended [Feature] Block API API that allows to express the block paradigm. Needs Testing Needs further testing to be confirmed. labels Dec 1, 2018
@talldan talldan removed the Needs Testing Needs further testing to be confirmed. label Jul 25, 2019
@talldan
Copy link
Contributor

talldan commented Jul 25, 2019

We tested this during the core editor triage (https://wordpress.slack.com/archives/C02QB2JS7/p1564035774193100 - slack link, requires signup to slack).

I was able to reproduce the issue.

My hunch is that it might be related to the timing of when the block is unregistered. Potentially the editor has already loaded the post and thinks the verse block is available, thus it displays the block without issue. I'm not completely sure when the right time to unregister a block is, would have to look that up.

I still think this is a bug though, so leaving open.

@mrwweb
Copy link
Author

mrwweb commented Sep 13, 2019

By no means do I think this resolves the issue, but @mcshaman provided a helpful temporary workaround that hides blocks from the Inserter Menus but doesn't actually unregister them, thereby avoiding errors.

@jakewhiteley
Copy link

This is also causing me issues.

If a block is already present in the content, then you get a fatal error instead of a core/missing block.

Like OP, I am calling unregisterBlockType within a window.wp.domReady callback as per the official documentation.

@dcblundell
Copy link

As above.

Noticing that when I try wp.blocks.unregisterBlockType(blockId) in the web inspector, targetting a block in use, some blocks will disappear from the editor window, and sometimes they remain. In both cases, the function returns the block, indicating it was successfully unregistered.

@Mamaduka
Copy link
Member

Mamaduka commented Sep 5, 2022

@mrwweb, I'm no longer able to reproduce the issue.

I noticed that there were errors in the console caused by a new selector, but that will be fixed via ##43864.

@Mamaduka Mamaduka added the [Status] Needs More Info Follow-up required in order to be actionable. label Sep 5, 2022
@github-actions
Copy link

Help us move this issue forward. This issue is being marked stale since it has no activity after 15 days of requesting more information. Please add info requested so we can help move the issue forward. Note: The triage policy is to close stale issues that need more info and no response after 2 weeks.

@github-actions github-actions bot added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Sep 21, 2022
@kraftner
Copy link

So I was still able to reproduce this. Not if the unregistering happens right on wp.domReady but if it is done after that. Lets say something like

wp.domReady( function() {
    setInterval(function() {
        unregisterBlockTypes();
    }, 200);
});

It also doesn't crash immediately but any further interaction causes a Uncaught (in promise) TypeError: blockType is undefined

The unregistered blocks still show in the block list but with no name

image

When you focus the instance it disappears

image

Also you can't save the post because that causes the Uncaught (in promise) TypeError: blockType is undefined error as well.


The problem is that (if I remember correctly) directly running on wp.domReady causes issues with 3rd-party blocks that might only get registered later. So the slight delay may be a quite common pattern.

So this is still broken. The workaround mentioned in #12484 (comment) still works though.

@github-actions github-actions bot removed the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Sep 22, 2022
@ndiego ndiego removed the [Status] Needs More Info Follow-up required in order to be actionable. label Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

8 participants