Skip to content

Block sequential deprecations result in attribute data loss #59694

@andreg

Description

@andreg

Description

I'm having trouble with block deprecations being run sequentially on a dynamic block.

I have created the following example: a block with two initial attributes (name and surname), which get renamed one after the other (to firstName and lastName, respectively) in two separate deprecation functions. What happens is that the second one being run, overrides the outcome of the first, resulting in the first updated attribute being lost.

In our case, being the surname the first one being run in the deprecated.js exported array, only the name -> firstName attribute is correctly kept.

Here's a link to the repo where the issue is happening: https://github.com/andreg/BlockDeprecations

Specifically, here's a link to the deprecated.js file: https://github.com/andreg/BlockDeprecations/blob/main/src/deprecated.js

Step-by-step reproduction instructions

  1. Compile the block
  2. Create a new page with the following content: <!-- wp:test/test {"name":"John", "surname": "Doe"} /-->
  3. Refresh the page and check the block data wp.data.select( 'core/block-editor' ).getBlocks()[0].attributes

You'll see thatthe firstName attribute is present and with the correct value, while the lastName attribute is missing, infact it's still present the previous surname attribute.

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 6.4

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

    Labels

    Needs TestingNeeds further testing to be confirmed.[Feature] BlocksOverall functionality of blocks[Status] StaleGives the original author opportunity to update before closing. Can be reopened as needed.[Type] BugAn existing feature does not function as intended

    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