Skip to content

Support plain permalinks for REST URL construction#184

Merged
epeicher merged 3 commits into
trunkfrom
fix/plain-permalinks-rest-url
May 12, 2026
Merged

Support plain permalinks for REST URL construction#184
epeicher merged 3 commits into
trunkfrom
fix/plain-permalinks-rest-url

Conversation

@epeicher
Copy link
Copy Markdown
Collaborator

@epeicher epeicher commented May 12, 2026

Summary

Fixes #183. Several REST call sites built URLs by concatenating a path onto the injected restRoot (or a sibling usersUrl / insightsUrlBase / pluginsUrl / baseUrl key) 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=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.

What changed

  • New src/rest-url.ts exports joinRestUrl(restRoot, path), which handles both shapes:
    • Pretty: appends the path to the URL pathname.
    • Plain: appends the path to the existing rest_route query value and merges any query params from the path as separate searchParams.
  • Migrated every unsafe call site to use the helper:
    • src/posts-window/{rest,users-rest,user-edit-rest,user-edit-render,tags-cloud,categories-mindmap}.ts
    • src/content-graph/rest.ts
    • src/oauth-relay.ts
    • src/my-wordpress/rest.ts
    • src/desktop-files/preview.ts
    • src/desktop-files/rest.ts (the call() 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=0 and 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.").
  • 9 new unit tests pinning the helper's behavior on both permalink shapes (route-only, route+query, with/without trailing slashes, etc.).

PHP side already adapted to permalink structure via rest_url(), so no PHP changes were needed.

Test plan

  • npm run lint clean
  • tsc --noEmit clean
  • npm run test:js green (1125/1125, +9 new)
  • npm run build produces all bundles
  • Manual on local dev with Settings -> Permalinks -> Plain:
    • Posts window paginates, filters by tag / category / author
    • Users window opens, User Edit window loads with ?context=edit, save round-trips
    • My WordPress window opens and lists entities
    • Content Graph loads user / term / comment stats
    • Desktop icons render immediately on boot (no slow fallback)
    • Plugins window lists installed plugins (no "No route was found" toast)
  • Same flows still work on Post name permalinks (no regression).
Open WordPress Playground Preview

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.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 12, 2026

✅ WordPress Plugin Check Report

✅ Status: Passed

📊 Report

All checks passed! No errors or warnings found.


🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check

epeicher added 2 commits May 12, 2026 17:58
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.
@epeicher epeicher enabled auto-merge (squash) May 12, 2026 16:02
@epeicher epeicher merged commit fa0b999 into trunk May 12, 2026
5 checks passed
@epeicher epeicher deleted the fix/plain-permalinks-rest-url branch May 12, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plain permalinks not supported — REST calls 404 / malformed on default-WP installs

1 participant