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

Add a backward compatibility document #18499

Merged
merged 33 commits into from
Nov 14, 2019
Merged
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1,57 @@
# Backward Compatibility

Gutenberg follows the WordPress backward compatibility principles. This means backward compatibility for production public API is guaranteed. In some rare occasions breaking backward compatibility is unavoidable, in that case, the breakage should be as small as possible and be documented as clearly as possible to third-party developers using dev notes.
youknowriad marked this conversation as resolved.
Show resolved Hide resolved

## What qualifies as a production public API:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean "production-ready"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non just production. Some APIs are not production APIs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, should it be named production API then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean remove "public"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, no :D I meant: if these are not just "production APIs", why call them a "production public API"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 hmm... ya so I guess what you're distinguishing between here is packages built for production use vs packages built for development use and both have public apis but we only care about backwards-compatibility when it comes to packages built for production?

If so, then maybe the heading could be:

What qualifies as a public api for production use?

Again though, this is a nit. It's completely fine with me if you just want to resolve and use the text as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaning towards keeping it as is because it's the same term used in the previous sentence. We can iterate of course.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully get the term. You're saying that "production public API" consists of "production packages" and "development packages". This is a bit confusing to me. So the "development packages" is also "production public API"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

production public API is just public APIs exported from production packages

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The confusion comes from the fact that we never address the question:

"What qualifies as a production public API?".

Somewhere after defining the two types of packages we have to write:

"A production public API is a public API from a production package."


The Gutenberg code base is composed of two different types of packages:
- **production packages**: these are packages that are shipped as WordPress scripts (example: wp-components, wp-editor...).
- **development packages**: these are made out of developer tools that can be used by third-party developers to lint, test, format and build their themes and plugins (example: @wordpress/scrips, @wordpress/env...). Typically, these are consumed as npm dependencies in third-party projects.
youknowriad marked this conversation as resolved.
Show resolved Hide resolved

Backward compatibility guarantee only applies to the production packages as updates happen through WordPress upgrades.
youknowriad marked this conversation as resolved.
Show resolved Hide resolved

Production packages use the `wp` global variable to provide APIs to third-party developers. These APIs can be JavaScript functions, variables and React components.

### How to guarantee backward compatibility for a JavaScript function
youknowriad marked this conversation as resolved.
Show resolved Hide resolved

* The name of the function should not change.
* The order of the arguments of the function should not change.
* The function's returned value type should not change.
* Changes to arguments (new arguments, modification of semantics) is possible if we guarantee that all previous calls are still possible.

### How to guarantee backward compatibility for a React Component
youknowriad marked this conversation as resolved.
Show resolved Hide resolved

* The name of the component should not change.
* The props of the components should not be removed.
youknowriad marked this conversation as resolved.
Show resolved Hide resolved
* Existing prop values should continue to be supported. If a component accepts a function as prop, we can update the component to accept a new type for the same prop, but it shouldn't break existing usage.
youknowriad marked this conversation as resolved.
Show resolved Hide resolved
* Adding new props is allowed.
* React Context dependencies can only be added or removed if we ensure the previous context contract is not breaking.
* Class names and DOM nodes used inside the tree of the component are not considered part of the public API and can be modified. That said, changes to these should be done with caution as it can affect the styling. Keep the old ones if possible. If not, document these changes and write a dev note about the changes.
youknowriad marked this conversation as resolved.
Show resolved Hide resolved

### How to guarantee backward compatibility for a Block

* Existing usage of the block should not break or be marked as invalid when the editor is loaded.
* The styling of the existing blocks should be guaranteed.
* Markup changes should be limited to the minimum but If a block need to change its saved markup making previous versions invalid, a **deprecated version** for the block should be added.
youknowriad marked this conversation as resolved.
Show resolved Hide resolved

## Deprecations

As the project evolves, flaws to existing APIs are discovered, or updates are required to support new features. When this happens, we try to guarantee that existing APIs don't break and build new alternative APIs.
youknowriad marked this conversation as resolved.
Show resolved Hide resolved

To encourage third-party developers to adopt the new APIs instead, we can use the **deprecated** helper to show a message explaining the deprecation and proposing the alternative whenever the old API is used.
youknowriad marked this conversation as resolved.
Show resolved Hide resolved

## Dev Notes

Dev notes are [posts published on the make/core site](https://make.wordpress.org/core/tag/dev-notes/) prior to WordPress releases to inform third-party developers about important changes to the developer APIs, these changes can include:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Dev notes are [posts published on the make/core site](https://make.wordpress.org/core/tag/dev-notes/) prior to WordPress releases to inform third-party developers about important changes to the developer APIs, these changes can include:
Dev Notes are [posts published on the make/core site](https://make.wordpress.org/core/tag/dev-notes/) prior to WordPress releases to inform third-party developers about important changes to the developer APIs, these changes can include:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggested the opposite earlier because elsewhere we use "dev notes" in text. Only in a title words are capitalised, at the start of a sentence, or in a label.

* Promote new APIs.
youknowriad marked this conversation as resolved.
Show resolved Hide resolved
* Explain how some changes to existing APIs might affect existing plugins and themes (Example: classname changes...)
youknowriad marked this conversation as resolved.
Show resolved Hide resolved
* When breaking backward compatibility is unavoidable, explain the reasons and the migration flow.
youknowriad marked this conversation as resolved.
Show resolved Hide resolved
* When important deprecations are introduced (even without breakage), explain why and how third-party developers can update their code base in consequence.
youknowriad marked this conversation as resolved.
Show resolved Hide resolved

### Dev Note Workflow

- When working on a pull request and the need for a dev note is discovered, add the **Needs Dev Note** label to the PR.
- If possible, add a comment to the PR explaining why the dev note is needed.
- When the first beta of the upcoming WordPress release is shipped, go through the list of merged PRs included in the release and tagged with the **Needs Dev Note** label.
- For each one of these PRs, write a dev note and coordinate with the WordPress release leads to publish the dev note.
- Once the dev note for a PR is published, remove the **Needs Dev Note** label from the PR.