Describe the bug
When a reusable block has a reusable block embedded (containing the same ID) it throws a 500 error and the 'Reusable' tab disappears in WP 5.3.
To reproduce
1 Go to wp-admin/edit.php?post_type=wp_block&paged=1
Create a new reusable block. For this test, I am calling it 'Reusable Block Test'. You can call it anything you'd like. Publish and save, note the post ID from the URL.
Embed a new reusable block into the one you just created. Pick a random block.


You should get an error : 'Updating failed. or Updating failed. Error message: The response is not a valid JSON response. (note that it did update)
Go to Posts -> Add New. Open up the "Network" tab in Google Chrome. Clear anything there to get a fresh list.


Request URL: */wp-json/wp/v2/blocks?per_page=100&_locale=user
Request Method: GET
Status Code: 500
Remote Address: 127.0.0.1:8080
Referrer Policy: strict-origin-when-cross-origin

Expected behavior
Adding a block allows you to add previously created Reusable Blocks by using the "Reusable" tab
Desktop (please complete the following information):
Additional context
WP Version: 5.3
I was able to replicated this on a clean install.
Here is a video: http://bit.ly/2OFt2UW
and a screenshot:

I also encountered this error message:
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 262144 bytes) in /app/public/wp-includes/class-wp-block-parser.php on line 256 Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 262144 bytes) in /app/public/wp-includes/class-wp-fatal-error-handler.php on line 35
Props to @ladyzyra for doing some great sleuthing!
Until this is solved, how do you know that is the cause for your reusable block troubles? If you are a developer, look into the database and examine each listed reusable block, if you find one with ID - double-check it's not its own id. If it is delete the entry.
If you don't have access to the database
Discussed this quickly, I think our best bet here is to fail gracefully instead of trying to eliminate the possibility to create a loop. The possibilities of creation are endless including writing HTML.
Note that the duplicate issue https://github.com/WordPress/gutenberg/issues/21117 has some detailed steps for reproducing this.
Agree with Riad that we only need to fail gracefully here.
@noisysocks @youknowriad is self-referencing a valid use case? If not we could update the Reusable Block search logic to filter out self. If the approach sounds good I can create PR for this.
@noisysocks @youknowriad is self-referencing a valid use case?
No, it's not but I remember looking at this a long time ago and add a check before insertion is very complex:
These are all bad use-cases:
I worry about the added complexity compared to the value of the check and I might think adding a check post insertion/rendering is better. (showing a warning if we detect errors somehow).
In case it's a useful data point, we encountered this situation in the wild yesterday. A client of ours was editing an existing reusable block and managed to make it self-referential, thus cratering a number of posts. I only discovered what had happened after the fact, so I can't provide the exact sequence of steps they used, but the end result was a block whose wp_content was a wp:block reference to itself.
Closed #26542 as a duplicate.
edit: oops, didn't mean to close this one!
Please see #26951
Most helpful comment
Discussed this quickly, I think our best bet here is to fail gracefully instead of trying to eliminate the possibility to create a loop. The possibilities of creation are endless including writing HTML.