WordPress / gutenberg

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

Deprecations: break out multiple deprecations into multiple files #35412

Open glendaviesnz opened 2 years ago

glendaviesnz commented 2 years ago

What problem does this address?

  1. Currently block deprecations are all contained in a single file, and within that file each deprecation is declared as an object literal within an array. This presents the following issues as the number of deprecations for blocks increases (eg. Cover and Gallery have 6+ deprecations):
  1. As well as the manageability of the single file the other potential issue with deprecations is the fact that shared utils imported and used by the block save method continue to be imported from the main block code by the deprecation save methods. This can lead to tricky to find bugs with deprecations when those shared methods are changed. In order for deprecations to be successfully applied and their save method to return a valid block all the methods used by the save function need to continue to return the same output as when that version was the current one.

What is your proposed solution?

The above issues could be mitigated by:

Using this approach, standard IDE functionality can be used to easily identify which version of methods is used by which deprecation, eg.

shared

There is an example PR here which shows how this approach would look with the Cover block.

An alternative to this approach is to follow the structure adopted by Jetpack which is to have each deprecation in its own sub folder, which might allow better isolation of any additional utility code used by a specific deprecation's save method.

It would be good to hear what others think, eg.

Mamaduka commented 2 years ago

Thanks for the proposal, @glendaviesnz. I agree this would make deprecation management more straightforward.

allow better isolation of any additional utility code used by a specific deprecation's save method.

Those can be inlined in the version desperation file itself. That being said, I don't have strong opinions about the directory structure.