REST API: Sync /themes endpoint with Core's#23321
Conversation
|
Size Change: +35 B (0%) Total Size: 1.13 MB
ℹ️ View Unchanged
|
Addison-Stavlo
left a comment
There was a problem hiding this comment.
I tested this on 5.4 and master, the theme preview works as expected. Although I noticed this still works on current Gutenberg master branch, so this isn't fixing the theme preview? That's more of a smoke test to ensure the endpoint is still working?
Uh, you're right, there was a mistake in my instructions 😅 I've updated them now, I hope they make more sense now. They're still a bit complex -- we're basically comparing the output
|
|
Related: WordPress/wordpress-develop#264 |
| /> | ||
| <div className="edit-site-template-switcher__theme-preview-description"> | ||
| { truncate( description, { | ||
| { truncate( description.raw, { |
There was a problem hiding this comment.
Why isn't this the rendered version? The rendered version has wptexturize applied which handles things like curly quotes.
There was a problem hiding this comment.
My thinking was that the rendered version might contain HTML markup (stuff like <a /> or <em />) and would thus require us to __dangerouslySetInnerHtml to render it in React, which I wanted to avoid.
There was a problem hiding this comment.
It could, but it has wp_kses applied to be safe.
There was a problem hiding this comment.
Hmm, okay. I can see that for name, but with description here, there's an extra complication -- I'm truncate()ing, so we might end up with an opening HTML tag that messes up the rest of the markup 😕
There was a problem hiding this comment.
It looks like this could be possible with https://github.com/arendjr/text-clipper.
There was a problem hiding this comment.
Thanks, I wasn't aware of that! I think it's worth considering, but since we'd require an extra dependency for truncating the theme description down to ~120 chars, it might be controversial, so I'd rather not block this PR on it. We can open a separate issue/PR tho!
| <div className="edit-site-template-switcher__theme-preview"> | ||
| <span className="edit-site-template-switcher__theme-preview-name"> | ||
| { name } | ||
| { name.raw } |
There was a problem hiding this comment.
Why not rendered here as well? We get a safe fallback if the theme doesn't have a proper name listed.
There was a problem hiding this comment.
I think we should, that matches core's behavior see wp_prepare_themes_for_js.
|
I left some comments. I think we also need to consider the value of I am somewhat worried about making sure these stay in sync with Core. Have we ruled out requiring trunk for experimental features like this? |
Ah yeah, good point. I'll modify it to that effect 👍
I haven't really been in any conversation regarding that. TBH I'd rather avoid that -- I think it's fair to require a rock-solid implementation of e.g. a REST API endpoint in Core, but I was happy that it wasn't a blocker for developing some code on the client side that depended on it. Getting a preliminary version of the endpoint additions into Gutenberg allowed me (and others) to iterate quickly on the client-side code, while I was at the same time refining the Core implementation of the endpoint (in accordance with feedback). Overall, it took about 8 weeks until the latter was ready to be merged; that's the amount of time I would've had to wait if we had required those changes to be in Core's trunk for Gutenberg to use it. |
I think I did a bad job of explaining what I meant. The idea would still be that code lives in Gutenberg first, but once it is merged to trunk, trunk would be required. That way we don't have to worry about any future changes to trunk making it back to the Gutenberg plugin or the syncing back to Gutenberg from Core was incorrect. So the development flow would be...
|
Right, thanks for clarifying! But wouldn't that mean that once a new version of the Gutenberg plugin is released after 3., it could no longer be tested on a stable WordPress Core install? |
|
we still need to maintain compatibility in the Gutenberg plugin with 5.4 even after 5.5 lands. |
I just tested adding some |
|
@TimothyBJacobs I think I addressed your feedback, would you mind giving this another look? 😊 🙏 |
I'll move this to a separate issue, but I think doing this for some things will be completely impossible, like the navigation screen due to how batch requests need to be implemented in Core. I also think its going to prove difficult to keep the larger REST API changes in sync.
Looks good. I still wish we'd use the same data ( rendered description ) that we do in wp-admin, but I can see how that complicates things. |
I might be missing something here, but is this related to the changes in this PR? The way we're adding fields to the
Thank you! In #23321 (comment), I'm suggesting a follow-up issue/PR to further look into that 🙂 |
|
The test setup has changed and tests seem to be stuck. I'll rebase. |
ec6f16d to
870324e
Compare
Description
In #21578, I added a few fields to Core's
/themesendpoint, for use by the Site Editor's Template Switcher (see both #21578 and #21768). I then submitted those changes as a PR against Core. That PR underwent a number of modifications and was eventually merged; the new fields will be part of the/themesendpoint exposed by Core starting from the next WP release.This PR updates the fields added by Gutenberg to follow the same semantics, as well as the callsites that use that endpoint.
Fixes #23054.
How has this been tested?
Test the template switcher's theme preview as described in #21768. You need to do this both with WP 5.4, and WordPress' current
masterbranch. Verify that the theme preview works in both cases.Alternatively:
masterbranch, and make sure you're using it with WordPress' latestmasterbranch./themesendpoint, and to suppress Gutenberg's addition of fields to the/themesendpoint (so that we get the/themesendpoint to reply with the fields that are defined in Core):/themesendpoint's response, and copy it (in JSON format) to a text editor.lib/rest-api.phppatch, but keep thelib/edit-site-page.phppatch.theme_supports, which predates REST API: Themes: Expose some additional basic fields wordpress-develop#222) in order to rely on Gutenberg to add those fields:Types of changes
Update to sync with Core.
Checklist: