Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecations: break out multiple deprecations into multiple files #35412

Open
glendaviesnz opened this issue Oct 7, 2021 · 1 comment
Open
Labels
[Feature] Block Validation/Deprecation Handling block validation to determine accuracy and deprecation [Type] Enhancement A suggestion for improvement.

Comments

@glendaviesnz
Copy link
Contributor

glendaviesnz commented Oct 7, 2021

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):
  • When debugging deprecation issues it is hard work going through the likes of a 500+ line Object[] definition working out where one deprecation starts and another finishes
  • For devs new to deprecations there is no indication in this structure that the newest deprecation is the first in the array and the oldest is last, and this ordering is of reasonable importance in order to optimise deprecation performance
  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:

  • Breaking deprecations up into separate files within a deprecations/ folder once more than a single deprecation is added
  • Naming each deprecation object as the version of the block it applies to, and then adding this to the deprecation array, which gives an indication of the required order, eg. const deprecations = [v3, v2, v1];;
  • In the deprecations folder include a shared.js file to which the local imports used by the deprecation can be added to ensure they remain static.
  • As new deprecations are added that use different versions of a shared local method it can be added to this file directly under the existing one with V2, etc. added to the method name.

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.

  • Is this a problem that we should be looking to fix?
  • If so are the above suggested fixes feasible?
  • Or, is there a better way to improve the usability/maintenance of deprecations?
@glendaviesnz glendaviesnz added [Type] Enhancement A suggestion for improvement. [Feature] Block Validation/Deprecation Handling block validation to determine accuracy and deprecation labels Oct 7, 2021
@Mamaduka
Copy link
Member

Mamaduka commented Oct 7, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block Validation/Deprecation Handling block validation to determine accuracy and deprecation [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

2 participants