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

Image Editor: Stabilize endpoint #23536

Merged

Conversation

TimothyBJacobs
Copy link
Member

Description

  • Changes the namespace to wp/v2 and the endpoint to /media/<id>/edit.
  • Makes some code style changes for Core.
  • Includes REST API error message in error notice.
  • Checks if mime type is valid.

How has this been tested?

Manually tested editing an image.

Types of changes

Breaking change.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@TimothyBJacobs TimothyBJacobs added REST API Interaction Related to REST API [Block] Image Affects the Image Block labels Jun 27, 2020
@TimothyBJacobs TimothyBJacobs self-assigned this Jun 27, 2020
@TimothyBJacobs TimothyBJacobs force-pushed the change/image-editor-route branch from 5289888 to 5519045 Compare June 27, 2020 19:00
@TimothyBJacobs
Copy link
Member Author

Copy over feedback.
https://github.com/WordPress/gutenberg/pull/23369/files#r444990474
https://github.com/WordPress/gutenberg/pull/23369/files#r444998308
https://github.com/WordPress/gutenberg/pull/23369/files#r445003720

Made some of those changes. Attachments aren't a hierarchical post type, so it wouldn't have a parent. I think I'm going to save the args change to when we merge into Core since it'll be going into the existing attachments controller endpoint.

@azaozz
Copy link
Contributor

azaozz commented Jun 27, 2020

The file header needs updating too (copy/paste error?) https://github.com/WordPress/gutenberg/pull/23536/files#diff-291983831703ba4378ca5e0aafccb6f8R3-R4

@TimothyBJacobs
Copy link
Member Author

Fixed the file header.

@azaozz azaozz self-requested a review June 27, 2020 22:19
Copy link
Contributor

@azaozz azaozz left a comment

Choose a reason for hiding this comment

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

Looks good.

@TimothyBJacobs TimothyBJacobs merged commit 315707c into WordPress:master Jun 28, 2020
@github-actions github-actions bot added this to the Gutenberg 8.5 milestone Jun 28, 2020
@TimothyBJacobs
Copy link
Member Author

Don't you think this has already been answered with the unstable and private php JS API already shipping in WordPress?

No I don't. We really don't have private APIs in PHP. There are a couple of tiny functions which are in no way comparable to an entire REST API endpoint. The closest candidate is the list table API, and I'll mention again, we've maintained BC for it.

Again, I'm not strongly against the idea, but IMO it needs wider discussion.

@chrisvanpatten
Copy link
Contributor

Agreed with @TimothyBJacobs — this is a decision that needs to come from a wider discussion with more core contributors and committers. It's not to say it can't or shouldn't happen, just that it's something that absolutely merits a more formal understanding of what the implications are and how to manage the risk appropriately.

@spacedmonkey
Copy link
Member

I agree with @TimothyBJacobs . We discussed this matter in the #core-restapi slack channel here. As a rule, once something goes into core, it basically never goes out. A feature like image editing, WILL be useful by plugin developers, even if we nicely ask them not to.

If a feature isn't ready for core, it should go in. It can be developed in a gutenberg or a feature plugin. My menus endpoint has been in development for a year. As much as I want it in, until it ready for core and completely stable, it doesn't go in :(

@chrisvanpatten
Copy link
Contributor

chrisvanpatten commented Jun 29, 2020

And to the point of unstable JS functionality, the way I rationalize it is that that unstable functionality is that it comes via an external package that gets bundled with core — it just happens to be that those external packages are also developed by the WordPress team. It's harder to make that logic leap with code that's going to be directly maintained in core/Trac.

There have already been people asking about using these endpoints outside of Gutenberg. Without a formal discussion and well-communicated understanding of how core intends to treat these endpoints it's very likely they'll be used and abused the same way that other "private" APIs (like the List Table API) have been.

@youknowriad
Copy link
Contributor

I understand your point of view. Third-party users want these unstable/experimental APIs.
I can also see how this feels like a big change for you as the gate keepers of the endpoints. Even if endpoints are just another kind of API in WordPress and WordPress already has internal and experimental.

That said,it's as important to aknowledge these points:

  • third-party users want stability and more importantly they want clear expectations communicated. If an API is not considered ready and there's no way to "hide it" from public API, it should be clearly communicated as unstable/experimental ortherwise you're going to hurt these same third party users if you do breaking changes later or hurt WordPress Core if you have to keep broken APIs.
  • WordPress need to ship features and sometimes this means having internal APIs and sometimes this means internal APIS that can't be entirely "hidden".

@chrisvanpatten
Copy link
Contributor

@youknowriad I think the point we're trying to raise is that historically WordPress core has not had a formal policy around experimental features. Given WordPress' historical commitment to backward compatibility in core code, it seems reasonable to discuss in a core meeting (perhaps even this week) to understand community concerns and what the team here is looking to accomplish, and determine a policy. There are likely other concerns here that we're not thinking of: what effect this might have on auto-updates inadvertently breaking things? What if other parts of core adopt the API (since technically they're first party consumers and can adopt it) but have their implementations broken? Perhaps there are other teams who would like to create experimental or unstable endpoints who have specific concerns that need to be accommodated as well.

@youknowriad
Copy link
Contributor

I think the point we're trying to raise is that historically WordPress core has not had a formal policy around experimental features.

Allow me to disagree with this. Gutenberg has set a formal policy for this for some time now, and Gutenberg is WordPress Core as far as I know. We also didn't come up with this in Gutenberg, we just followed what was already done on PHP, we just put it in a more formal way to help developers know how to mark their API as experimental or unstable.

That said, I understand the point about making this more visible and raising more awareness. That's definitely needed.

@chrisvanpatten
Copy link
Contributor

@youknowriad I don't think it's ever been communicated that this policy applies to all core code. If that's the case I think it needs to be clearly communicated to team reps and to core committers, as this discussion pretty clearly shows at least some portion of those folks were not aware of this.

@chrisvanpatten
Copy link
Contributor

It should also probably be moved out of the block editor documentation and into the Core handbook.

@spacedmonkey
Copy link
Member

I think that it is not for the few people on this thread to decide this. This is a fundamental change on how WordPress and 35%+ of the internet is developed. If this is changing it is need to written up a proposal and get community feedback. After waiting a while to get feedback, only then can we really have this discussion.

@earnjam
Copy link
Contributor

earnjam commented Jun 29, 2020

I think there is a difference between small internal/narrowly-focused functions flagged with an @access private in the docblock and a fully functional REST API endpoint.

To my knowledge, we haven't shipped a full PHP class as private since WP_List_Table and I think many would generally view that as something that can't really be changed at this point despite it being marked as private and there being warnings in other documentation. In fact, those warnings aren't even listed anywhere on the new Code Reference.

If we don't feel confident that something is "ready" for core merge, then it should live in the plugin, where it can stay experimental until it's stable enough for a merge. In this context, "ready" means that we're willing to take on the burden of not breaking things just because we want it to work differently in the future. That to me is the point of feature plugins. The plugin is the experimental label.

I'm not saying experimental APIs are bad. Just that to me it doesn't align with traditional core project philosophies.

I also understand that this has been done with JS in Gutenberg for a while, but I have always disagreed with those things coming over into core still labeled as experimental. I think Gutenberg has initiated a fundamental shift in how WP thinks about backward compatibility, but it's mostly been confined to the work inside the Gutenberg repo. It spills over into core through the packages being consumed, but in general it's been isolated to that.

If we're going to move toward a looser philosophy of shipping bigger—and what will be likely popular—APIs that we plan to break in the future, then I think it would be good to see some guidance from the project lead about where the project's responsibility toward backward compatibility ends.

@youknowriad
Copy link
Contributor

I think there's a misunderstanding here. The feature is not the "endpoint", it's the image editing and it's finished and stable. But the feature can't be shipped without leaking an API that we don't want to leak specifically to ensure backward compatibility.

@spacedmonkey
Copy link
Member

I think there's a misunderstanding here. The feature is not the "endpoint", it's the image editing and it's finished and stable. But the feature can't be shipped without leaking an API that we don't want to leak specifically to ensure backward compatibility.

The feature is the REST API + the UI to use that API. The UI is meaningless without the REST API to do the work on changing and saving the image. Anything that goes into core needs unit tests and for the community to test the functionality. What is the point of merging functionality we are going to rewrite later? It is a waste time to test this to the scale that 35%+ of the internet deserves, to then rewrite it months later.

We are being kinder to the community, by shipping something that can remain in core, has solid test coverage and will not change.

@earnjam
Copy link
Contributor

earnjam commented Jun 30, 2020

These two statements seem to contradict since the image editing is dependent on the endpoint and might change as soon as 5.6:

The feature is not the "endpoint", it's the image editing and it's finished and stable.

This endpoint might change drastically for 5.6 or even be avoided entirely (if we edit in JS). It shouldn't be used by plugins for now.

Regardless of what core feature is using the endpoint, if we have serious concerns that we are going to need to break it, I think it's a sign it's not ready to ship in core. Plugins will use it whether we want them to or not. You can't prevent it from leaking once it's in core, but the Gutenberg plugin drastically limits that exposure.

This is something very different in WordPress vs more contained/controlled software. Once something is in the wild, we can't expect to control it with a label. The more experimental APIs we ship then break, the more dangerous core updates become for people because we can't count on plugins to not leverage them. The average user isn't going to know or care that a plugin was using an experimental API, just that they updated and their site broke.

I don't think we can continue our goal of moving toward widespread trust in automatic updates while simultaneously shipping unstable APIs. So I think it's a question of risk vs project goals and core philosophies.

@youknowriad
Copy link
Contributor

youknowriad commented Jun 30, 2020

Regardless of what core feature is using the endpoint, if we have serious concerns that we are going to need to break it, I think it's a sign it's not ready to ship in core.

We have concerns about breaking the endpoint not the feature (the image resizing). I don't see any contradiction there, it's just implementation details that can change.

@youknowriad
Copy link
Contributor

I'm not saying experimental APIs are bad. Just that to me it doesn't align with traditional core project philosophies.

I also don't feel very good when reading this kind of sentence. Gutenberg philosophies are Core philosophies whether we like them or not. It's been 4 major releases that it's on Core now.

@youknowriad
Copy link
Contributor

Another thing, the decision to make this endpoint stable comes from the REST API team, so the Rest API team considers the endpoint stable. I personally don't know (or even don't care much about this), what I care about is that the "editing image" feature is stable and should be released and that private APIs (no matter what API is this) are a good thing in general.

@chrisvanpatten
Copy link
Contributor

Gutenberg philosophies are Core philosophies whether we like them or not. It's been 4 major releases that it's on Core now.

Gutenberg has always lived at an arms' length from core, with its own issue management, project management system, a separate contributor handbook, and major development decisions made in isolation and often in private. It's hard for me to make the leap to "Gutenberg changes are pulled into WordPress core, therefore WordPress core must adopt Gutenberg philosophies".

Now I want to be explicitly clear — I'm not arguing in favor or against unstable APIs. Yes, I have my own opinions, but the only point I really care about is communication. I know WordPress isn't a democracy, and I do grant that there is a lot that core can learn from Gutenberg, but it just feels like these things should be communicated in a formal way, either via a core dev chat or a Make post or in the core handbook so all contributors and users have a crystal clear understanding of how the project thinks. I don't think that's too much to ask.

@TimothyBJacobs
Copy link
Member Author

Another thing, the decision to make this endpoint stable comes from the REST API team, so the Rest API team considers the endpoint stable.

Reiterating my comment from above.

I also don't think the discussion is particularly relevant for this endpoint. The endpoint and actions were designed to be forwards compatible with a different request format.

If we end up doing 100 percent of the editing in JS, I don't think that means we'd need to remove the endpoint. The media team seems to be onboard with an editing endpoint in general.

If it is shipped as __experimental then we are guaranteeing a BC break. That's the difference.


what I care about is that the "editing image" feature is stable and should be released

For the editing image feature to be considered stable, the backend code also must be considered stable. They can't be separated like that.

Even if endpoints are just another kind of API in WordPress and WordPress already has internal and experimental.

Gutenberg JavaScript does, but Core PHP does not.

WordPress need to ship features and sometimes this means having internal APIs and sometimes this means internal APIS that can't be entirely "hidden".

WordPress has done quite well with a high commitment to backwards compatibility. What got us here won't get us there etc..., but that also doesn't mean we should just break backwards compatibility when unnecessary.

A common argument I've seen for why Gutenberg needs a more lenient BC policy is because of bundle size. This clearly isn't a consideration for PHP APIs.

or hurt WordPress Core if you have to keep broken APIs.

If an API is a candidate for being broken, it shouldn't be shipped in Core to begin with.

Gutenberg has set a formal policy for this for some time now,

As @chrisvanpatten points out, it pretty clearly applies to the Gutenberg ( JS ) code base.

And while the policy is formally written, I have had a hard time finding where it was formally discussed. It looks like it was made in an impromptu decision in #core-editor. And was documented without much discussion.

The clarification of the docs also did not garner a lot of feedback.

I think part of the reason for that is because it was about facilitating the block editor's goals by the block editor team. With the expectation that it wouldn't apply to Core's PHP BC philosophy.

The difference in feedback is really noticeable compared to things like https://make.wordpress.org/core/2019/12/09/proposed-javascript-coding-standards-revisions-for-prettier-compatibility/


If you look at the slack backscroll when we discussed this, I think it's clear I'm not opposed to this idea and I'll also echo Chris' statement about communication.

@earnjam
Copy link
Contributor

earnjam commented Jun 30, 2020

And while the policy is formally written, I have had a hard time finding where it was formally discussed. It looks like it was made in an impromptu decision in #core-editor. And was documented without much discussion.

It also looks like the original intent was to remove the flag when merging to core.

image

@spacedmonkey
Copy link
Member

Here is the question, how do we plan to break this API? Different params or names? We could refactor the internal logic and still keep BC. If it is adding more options then, this again can be done without breaking anything.

There are apis in core we have had to do some weird stuff to maintain BC, we could do this here.

@TimothyBJacobs
Copy link
Member Author

Here is the question, how do we plan to break this API? Different params or names? We could refactor the internal logic and still keep BC. If it is adding more options then, this again can be done without breaking anything.

There are apis in core we have had to do some weird stuff to maintain BC, we could do this here.

Yeah because this is an RPC endpoint, with our current endpoint design I'm not too worried about maintaining BC.

@azaozz
Copy link
Contributor

azaozz commented Jun 30, 2020

Wow, lots of (partially related) discussion here :)

Perhaps unstable, internal or private are better prefixes.

...the only point I really care about is communication.

My take would be to make it "extremely clear" that it is "doing it wrong" to use. Perhaps wp/v2/__private/*? Then there will be no chance a developer wouldn't notice they are doing something "wrong" and they may end up getting a 404, eventually :)

Currently there are 340 private functions in core, out of 3447. 10% is a significant number. It's true that WordPress is trying to keep them working in a backwards compatible way, and that unneeded private functions are deprecated, not removed. The same approach can probably be applied to the API: deprecated functions and params typically throw "doing it wrong" notices.

@ellatrix ellatrix mentioned this pull request Jul 1, 2020
12 tasks
@ajlende ajlende mentioned this pull request Jul 1, 2020
6 tasks
@ellatrix
Copy link
Member

ellatrix commented Jul 2, 2020

There are apis in core we have had to do some weird stuff to maintain BC, we could do this here.

Are you up for doing it and maintaining it? :)

@TimothyBJacobs
Copy link
Member Author

In the interest of making a decision here, unless a lead says no :), my plan at this point is to merge this version of the endpoint as a proper wp/v2 endpoint.

Are you up for doing it and maintaining it? :)

Yes, I'm not very worried about maintaining BC with our current design. We can seamlessly transform the old request format to the new request format. And we aren't passing the request object to any hooks in the endpoint.

@azaozz
Copy link
Contributor

azaozz commented Jul 3, 2020

my plan at this point is to merge this version of the endpoint as a proper wp/v2 endpoint.
...
We can seamlessly transform the old request format to the new request format.

Sounds good. Shall we add the end point to trunk now? (The class is conditionally loaded in Gutenberg). Then this will be using trunk's end point. Not a big difference but when committed to trunk it may bring some more feedback, especially about the new filter on $new_image_meta and whether post_content and excerpt would have to be copied from the parent attachment.

@TimothyBJacobs
Copy link
Member Author

Yep! Working on that patch today.

@TimothyBJacobs
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Image Affects the Image Block REST API Interaction Related to REST API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants