fix: resolve the REST index locally on namespaced sites - #617
Draft
dcalhoun wants to merge 1 commit into
Draft
Conversation
XCFramework BuildThis PR's XCFramework is available for testing. Add the following to your .package(url: "https://github.com/wordpress-mobile/GutenbergKit", branch: "pr-build/617")Built from ef26163 |
Gutenberg's `root`/`__unstableBase` entity requests the REST API index (`/`) during editor initialization. On namespaced sites the path has no segments for the namespace middleware to rewrite, so the request targets the API host's root, which serves no index and fails. Resolve the entity locally with the site URL the host already provides. The remaining fields are either unavailable on namespaced sites or read from the `site` entity by the blocks that use them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017jPW5y3FrRywuHHn3gAHgu
dcalhoun
force-pushed
the
fix/skip-rest-index-on-namespaced-sites
branch
from
September 2, 2026 16:13
a1725eb to
ef26163
Compare
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.
What?
Resolve Gutenberg's REST API index request locally on namespaced sites instead of sending it to the API host's root.
Stacked atop #614; merge that first.
Why?
The editor fails a request on every launch for a namespaced site. Gutenberg's
root/__unstableBaseentity fetches the REST API index (/?_fields=...) during initialization. That path has no segments forapiPathModifierMiddlewareto insert the namespace into, so the request targets the bare API host root, which serves no index. Over HTTP origins (the Vite dev server, Android) it fails CORS preflight; fromfile://on iOS it follows a redirect to a docs page and fails JSON parsing.The only unconditional consumer,
useBlockEditorSettings, reads image sizes for client-side media processing, which GutenbergKit does not enable. The Site Title, Tagline, and Logo blocks read thesiteentity when the user can edit settings and only fall back to this record otherwise. No namespaced route serves the index, so there is nothing to redirect to.How?
Add
siteIndexMiddlewaretoconfigureApiFetch. For GET requests to/on a site with a configured API namespace, it resolves withhomeandurlfrom the host'ssiteURLrather than callingnext. Every other request passes through unchanged. It runs after the preloading middleware so a host-supplied index entry still takes precedence.Testing Instructions
Tip
Use the bundled build rather than the Vite dev server for step 4. Some hosts answer the index request from a dev-server origin with a 429 that carries no CORS headers, which the browser reports as a CORS failure unrelated to this change.
make buildand launch the demo app against a namespaced site (e.g., WordPress.com Simple)./?_fields=...) appears and the editor loads normally.<siteApiRoot>/?_fields=...and succeeds.npm run test:unit -- src/utils/api-fetch.test.jsExample root
/?_fields=...request:Accessibility Testing Instructions
No UI changes.
🤖 Generated with Claude Code
https://claude.ai/code/session_017jPW5y3FrRywuHHn3gAHgu