Skip to content

fix: Resolve dev server CORS errors and falsy post id blocking editor render#317

Merged
jkmassel merged 2 commits intointegrate/wp-androidfrom
fix/cors-dev-server-origin
Feb 10, 2026
Merged

fix: Resolve dev server CORS errors and falsy post id blocking editor render#317
jkmassel merged 2 commits intointegrate/wp-androidfrom
fix/cors-dev-server-origin

Conversation

@dcalhoun
Copy link
Member

What?

Two fixes that resolve the Android editor failing to render when using a local dev server via GUTENBERG_EDITOR_URL.

Why?

After the native CORS proxy was added in cad54a1, using a local dev server (GUTENBERG_EDITOR_URL) caused two issues:

  1. CORS errors: The Access-Control-Allow-Origin header was hardcoded to https://appassets.androidplatform.net, which doesn't match the dev server origin (e.g., http://192.168.0.114:5173). The browser rejected all proxied API responses.
  2. Editor never becoming ready: __unstableIsEditorReady() returns !!state.postId, so a post id of 0 (falsy) keeps the editor permanently stuck returning null. The host app was providing id: 0, which passed through unchecked.

How?

  1. CORS fix (GutenbergView.kt): addCorsHeaders now derives the origin from BuildConfig.GUTENBERG_EDITOR_URL when set, falling back to the bundled asset origin otherwise.
  2. Post id fix (bridge.js): Changed ?? to || for post id fallback in getPost(), so all falsy ids (including 0) fall back to -1, consistent with the existing default path.

Testing Instructions

  1. Set GUTENBERG_EDITOR_URL=http://<your-ip>:5173/ in android/local.properties
  2. Run make dev-server
  3. Build and run the Android app on a device/emulator
  4. Verify the editor loads and renders without CORS errors in Logcat

Accessibility Testing Instructions

No UI changes.

The CORS proxy in `addCorsHeaders` was hardcoded to
`https://appassets.androidplatform.net`, which is correct for
bundled assets but causes CORS failures when using a local dev
server via `GUTENBERG_EDITOR_URL`. The browser rejects the
proxied responses because `Access-Control-Allow-Origin` doesn't
match the dev server origin.

Derive the origin from `GUTENBERG_EDITOR_URL` when it's set,
falling back to the bundled asset origin otherwise.
`__unstableIsEditorReady()` returns `!!state.postId`, so a post
id of `0` keeps the editor permanently in a "not ready" state.

Use `||` instead of `??` to fall back to `-1` for all falsy ids
(not just null/undefined), matching the existing fallback path.
@dcalhoun dcalhoun added the [Type] Bug An existing feature does not function as intended label Feb 10, 2026
@dcalhoun dcalhoun marked this pull request as ready for review February 10, 2026 17:42
@dcalhoun dcalhoun requested a review from jkmassel February 10, 2026 17:42
@jkmassel jkmassel merged commit 12af282 into integrate/wp-android Feb 10, 2026
8 checks passed
@jkmassel jkmassel deleted the fix/cors-dev-server-origin branch February 10, 2026 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants