Support plain permalinks for REST URL construction#184
Merged
Conversation
Several REST call sites built URLs by concatenating a path onto the injected `restRoot` (or a sibling `usersUrl` / `insightsUrlBase` key) and assumed the pretty-permalink shape (`/wp-json/...`). On sites configured with Settings -> Permalinks -> Plain, `rest_url()` emits the query-string shape (`?rest_route=/...`); concatenating `?context=edit` or `?per_page=10` onto that produced two `?` separators, and the URL parser collapsed the whole path into the `rest_route` value, dropping the trailing query params and causing 404s. Add a shared `joinRestUrl(restRoot, path)` helper that handles both shapes (path-segment for pretty, query-merge for plain) and migrate every unsafe call site to use it. PHP side already adapted to permalink structure via `rest_url()`, so no PHP changes were needed. Fixes #183.
✅ WordPress Plugin Check Report
📊 ReportAll checks passed! No errors or warnings found. 🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
Two bundles still concatenated `?context=…` / `?folder=…` onto a REST URL and broke under Plain permalinks: the desktop-files layer 404'd on `/desktop-mode/v1/files/placements?folder=0` (the visible symptom was desktop icons taking many seconds to appear, since the files layer fell back to a slower path), and the Plugins window showed "Could not load plugins: No route was found matching the URL and request method." Migrate both files to `joinRestUrl` from src/rest-url.ts: - src/desktop-files/rest.ts `call()` now joins `baseUrl` and `path` through the helper, so every placements / folders / associations endpoint inherits the fix. - src/plugins-window/rest.ts uses `cfg.restRoot` plus the relative `wp/v2/plugins[...]` path for the list / activate / deactivate / delete call sites.
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 #183. Several REST call sites built URLs by concatenating a path onto the injected
restRoot(or a siblingusersUrl/insightsUrlBase/pluginsUrl/baseUrlkey) and assumed the pretty-permalink shape (/wp-json/...). On sites configured with Settings -> Permalinks -> Plain (the WordPress default for fresh installs),rest_url()emits the query-string shape (?rest_route=/...); concatenating?context=editor?per_page=10onto that produced two?separators, and the URL parser collapsed the whole path into therest_routevalue, dropping the trailing query params and causing 404s.What changed
src/rest-url.tsexportsjoinRestUrl(restRoot, path), which handles both shapes:rest_routequery value and merges any query params from the path as separate searchParams.src/posts-window/{rest,users-rest,user-edit-rest,user-edit-render,tags-cloud,categories-mindmap}.tssrc/content-graph/rest.tssrc/oauth-relay.tssrc/my-wordpress/rest.tssrc/desktop-files/preview.tssrc/desktop-files/rest.ts(thecall()helper, so every placements / folders / associations endpoint inherits the fix; the visible symptom on Plain was desktop icons taking several seconds to appear because the files layer 404'd on/desktop-mode/v1/files/placements?folder=0and fell back to a slower path).src/plugins-window/rest.ts(list / activate / deactivate / delete; visible symptom was the Plugins window showing "Could not load plugins: No route was found matching the URL and request method.").PHP side already adapted to permalink structure via
rest_url(), so no PHP changes were needed.Test plan
npm run lintcleantsc --noEmitcleannpm run test:jsgreen (1125/1125, +9 new)npm run buildproduces all bundles?context=edit, save round-trips