fix: drop /wp-json/ prefix from REST_BASE so apiFetch paths resolve (#145)#148
Merged
Conversation
REST_BASE hardcoded a leading "/wp-json/", but apiFetch already prepends the REST root, so every editor REST call double-prefixed into "/wp-json/wp-json/datamachine/..." and 404'd (rest_no_route) — masked on some configured sites but broken in a bare environment. Set REST_BASE to the plain REST route "/datamachine/v1/socials". Also switch uploadCroppedImage() from raw fetch() (which hardcoded the same "/wp-json/" literal and the nonce) to apiFetch, so the REST root, nonce, and credentials resolve consistently. Verified end-to-end with the WP Codebox crop-modal smoke test against the rebuilt bundle with the harness shim removed: the editor now hits /wp-json/datamachine/v1/socials/auth/status (200), the cropper renders and works under React 19, 9/9 assertions pass, 0 doubled requests. Removes the now-unneeded double-path shim from the test harness. Fixes #145
Contributor
Homeboy Results —
|
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.
Summary
Fixes #145 — the
REST_BASEdouble/wp-json/prefix that 404'd every editor REST call.src/utils/api.tsdefinedREST_BASE = '/wp-json/datamachine/v1/socials'and passed it as theapiFetchpath.apiFetchalready prepends the REST root, so the resolved URL double-prefixed into/wp-json/wp-json/datamachine/...→404 rest_no_route. This was masked on some configured production sites but broke in a bare environment (e.g. WordPress Playground).Changes
REST_BASE→/datamachine/v1/socials(drop the/wp-json/literal). All apiFetch calls (auth/status,platforms,post,status/{id},auth/{platform}/disconnect) now resolve correctly against the REST root.uploadCroppedImage()→apiFetchinstead of rawfetch(). The raw call hardcoded the same/wp-json/literal and the nonce; using apiFetch resolves the REST root, nonce, and credentials consistently. apiFetch passes aFormDatabody through untouched, so the upload semantics are unchanged.build/index.js+index.asset.phpso the shipped bundle carries the fix.tests/wp-codebox/crop-modal-seed.php) — it only existed to work around this bug.Verification
Ran the
tests/wp-codebox/crop-modal.jsonsmoke test against the rebuilt bundle with the harness shim removed (WordPress trunk / React 19):Network evidence — the editor now hits the correct single-prefix path:
The cropper renders and works end-to-end with only the correct route registered, proving the fix resolves the gating REST call.
Notes
Fixes #145.