Skip to content

Self-nested blocks causing infinite recursion and crashing the editor #66090

Closed

Description

Description

With the changes in #65700, self-nested or circular-nested blocks could cause infinite recursion resulting in crashing the editor.

cc: @youknowriad

Step-by-step reproduction instructions

  1. Register self-nested or circular-nested blocks. For example:
// Self-nested block
window.wp.blocks.registerBlockType( 'test/self-nested-block', {
	title: 'Self-nested Block',
	parent: [ 'test/self-nested-block', 'core/group' ],
	save: () => {
		return '';
	}
} );

// Circular-nested blocks
window.wp.blocks.registerBlockType( 'test/self-nested-block-1', {
	title: 'Self-nested Block #1',
	parent: [ 'test/self-nested-block-2', 'core/group' ],
	save: () => {
		return '';
	}
} );

window.wp.blocks.registerBlockType( 'test/self-nested-block-2', {
	title: 'Self-nested Block #2',
	parent: [ 'test/self-nested-block-1' ],
	save: () => {
		return '';
	}
} );
  1. Attempt to open the Inserter from the header toolbar. Note that if the problematic blocks already exist in the page content, the block editor will immediately crash after registering the blocks.

Note that if a visible parent block comes first, e.g. [ 'core/group', 'test/self-nested-block-2' ] instead of [ 'test/self-nested-block-2', 'core/group' ], the infinite recursion will not occur.

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 6.6.2
  • Gutenberg 19.4.0

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    [Feature] InserterThe main way to insert blocks using the + button in the editing interface[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions