Probe direct host for editor capability detection on Atomic sites#22883
Draft
jkmassel wants to merge 1 commit into
Draft
Probe direct host for editor capability detection on Atomic sites#22883jkmassel wants to merge 1 commit into
jkmassel wants to merge 1 commit into
Conversation
Fixes #22879. EditorSettingsRepository.fetchRouteSupport queried the WP.com proxy via getWpApiClient, but GutenbergView fetches wp-block-editor/v1/settings from the direct host. On Atomic sites without an application password those hosts can disagree, so the proxy would advertise the route, capability detection would say "theme styles supported," and the editor would then 404 trying to load it.
Collaborator
Generated by 🚫 Danger |
Contributor
|
|
Contributor
|
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #22883 +/- ##
==========================================
- Coverage 37.31% 37.31% -0.01%
==========================================
Files 2319 2319
Lines 124559 124576 +17
Branches 16921 16922 +1
==========================================
+ Hits 46484 46487 +3
- Misses 74319 74333 +14
Partials 3756 3756 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Description
Fixes #22879. The editor stalls partway through preloading on WP.com Atomic sites whose direct host doesn't expose
wp-block-editor/v1/settings, because capability detection reports "theme styles supported" via the WP.com proxy and then the editor 404s fetching that route from the direct host.Root cause
EditorSettingsRepository.fetchRouteSupportandGutenbergViewwere not talking to the same host on Atomic sites without an application password:WpApiClientProvider.getWpApiClient(site)returns the WP.com client wheneversite.isWPCom || site.isUsingWpComRestApi, soapiRoot()is queried viapublic-api.wordpress.com. Its route list driveshasRouteForEndpoint("/wp-block-editor/v1", "settings", ...).GutenbergViewuses the configuredsiteURL(the direct host) for its block-editor settings fetch, notsiteApiRoot.For Atomic sites without an application password those two hosts diverge — the proxy advertises routes the direct host doesn't expose — and we confidently tell the editor "theme styles is supported" right before the editor 404s on the direct host.
Fix
Detect against the host the editor will actually use. For WP.com Atomic without an application password, probe
apiRoot()on the direct host (${site.url}/wp-json) with an unauthenticatedWpApiClientrather than the WP.com proxy. All other site shapes keep the existinggetWpApiClient/getApiUrlResolverpath.WpApiClientProvider: NewgetDirectHostUrlResolver(site)andcreateUnauthenticatedDirectHostClient(site). The new client usesWpAuthentication.Noneand always points at${site.url}/wp-json, even ifwpApiRestUrlis set elsewhere. Not cached — these are one-off probe clients.EditorSettingsRepository.fetchRouteSupport: Selection logic moved intoprobeClientAndResolver(site). Forsite.isWPComAtomic && !site.hasApplicationPassword(), returns the direct-host pair; otherwise unchanged.What we explored
siteApiRootforwp-block-editor/v1/settings. Library-side change, and the project intent ("direct to the site as much as possible") cuts the other way.Scope
Strictly scoped to the WP.com-Atomic-without-app-password shape per #22879. Atomic + app password still routes through the WP.com client for detection even though the editor uses the direct host (with the app password) — that's a potential follow-up if it surfaces, but the original report didn't reproduce on that shape.
Testing instructions
Atomic site without an application password — direct host missing
wp-block-editor/v1/settings:wp-block-editor/v1/settings(awpcomstaging.comStorefront-themed site works — e.g.automatticwidgets.wpcomstaging.com).Atomic site with an application password (regression check):
Non-Atomic / Simple / self-hosted (regression check):
Unit tests:
./gradlew :WordPress:testJetpackDebugUnitTest --tests EditorSettingsRepositoryTest— passes (existing tests + 2 new tests covering the Atomic-no-app and Atomic-with-app-password paths).