Skip to content

Block Bindings: Post metadata persists after connected block is removed #65683

@artemiomorales

Description

@artemiomorales

Description

When metadata is created via blocks bound to custom attributes, the metadata persists after the block is removed. This can result in unexpected behavior, such as that metadata continuing to erroneously render in a template.

This discussion also touches on overall Block Bindings UX, and may have implications for how we model content with bindings in the post editor, and potentially the site editor.

Step-by-step reproduction instructions

1. Register some custom post meta. For an easy example, here's code to register a custom post type with related meta:
function register_video_post_type(): void {
	$args = array(
		'label'               => __( 'Videos', 'video-features' ),
		'description'         => __( 'Videos catalogue', 'video-features' ),
		'supports'            => array(
			'title',
			'editor',
			'author',
			'thumbnail',
			'revisions',
			'custom-fields',
		),
		'hierarchical'        => false,
		'public'              => true,
		'show_ui'             => true,
		'show_in_rest'        => true,
		'show_in_menu'        => true,
		'show_in_nav_menus'   => true,
		'show_in_admin_bar'   => true,
		'menu_position'       => 5,
		'can_export'          => true,
		'has_archive'         => true,
		'exclude_from_search' => false,
		'publicly_queryable'  => true,
		'capability_type'     => 'post',
		'menu_icon'           => 'dashicons-format-video',
	);
	register_post_type( 'video', $args );

	register_post_meta(
		'video',
		'director',
		array(
			'show_in_rest'      => true,
			'single'            => true,
			'type'              => 'string',
			'default'           => '[Director here]',
		)
	);

	register_post_meta(
		'video',
		'genre',
		array(
			'show_in_rest'      => true,
			'single'            => true,
			'type'              => 'string',
			'default'           => '[Genre here]',
		)
	);

	register_post_meta(
		'video',
		'length',
		array(
			'show_in_rest'      => true,
			'single'            => true,
			'type'              => 'string',
			'default'           => '[Length here]',
		)
	);

	register_post_meta(
		'video',
		'trailer_url',
		array(
			'show_in_rest'      => true,
			'single'            => true,
			'type'              => 'string',
			'default'           => '',
			'sanitize_callback' => 'sanitize_text_field',
			'revisions_enabled' => true,
		)
	);
}
add_action( 'init', 'register_video_post_type' );
  1. In a template for the post type, add a paragraph and bind it to one of the meta fields.
  2. Create a new post.
  3. In the post, add a paragraph and bind it to the same meta field as in step 2, and override the value.
  4. Delete the paragraph.
  5. View the post.
  6. See that the metadata is still visible.

Screenshots, screen recording, code snippet

removing-metadata.mp4

Environment info

  • Gutenberg 19.3 (trunk)
  • WP 6.6.2

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions