WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.49k stars 4.19k forks source link

Block Bindings: Send only edited values to the POST API requrest #64714

Open cbravobernal opened 2 months ago

cbravobernal commented 2 months ago

Description

Since 6.6, you can now edit the values of binded custom fields in the editor. If you do that, you send all the default values to de REST API. Fortunately, those values are not saved in DB.

Screenshot of what is being sent when I only edited the pokemon_typeto "Water Type"

Screenshot 2024-08-22 at 13 18 00

The rest of the fields are not connected in any block of the post.

Removing this from the fields can save some bytes sent to the server, meta fields can grow exponentially with plugins installed.

Step-by-step reproduction instructions

1) Register your meta.

register_meta(
        'post',
        'pokemon_attack',
        array(
            'show_in_rest'      => true,
            'single'            => true,
            'type'              => 'string',
            'default'           => 'Scratch',
            'object_subtype' => 'page',
        )
    );
    register_meta(
        'post',
        'pokemon_type',
        array(
            'show_in_rest'      => true,
            'single'            => true,
            'type'              => 'string',
            'default'           => 'Plant',
        )
    );

2) Create a post. Enable block bindings UI experiment. Connect a paragraph to any field created. Edit the field. 3) Save and the API request. 4) Check that the DB only contains the meta data updated, not the API request.

Environment info

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

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

gziolo commented 2 months ago

Since 6.6, you can now edit the values of binded custom fields in the editor. If you do that, you send all the default values to de REST API. Fortunately, those values are not saved in DB.

Removing this from the fields can save some bytes sent to the server, meta fields can grow exponentially with plugins installed.

Can you clarify what the issue needs to be solved here? The screenshot included shows the legacy meta boxes panel enabled, so it isn't clear if that applies to that interface or to the Save functionality triggered after changes were applied through the connected block attribute. If I follow correctly, everything works as intended, but the amount of the data sent could be reduced by skipping non-modified meta values, right?

cbravobernal commented 2 months ago

Sorry if it was not clear.

The legacy meta boxes panel in this case does not apply. Is only the save functionality after editing a connected field. Yes, everything works, but, as you mention, we can reduce the data sent doing what you mention.