Skip to content

feat(theme): refresh API explorer UX and add opt-in modern layout - #1709

Merged
sserrata merged 10 commits into
mainfrom
feat/theme-ux-refresh
Nov 9, 2026
Merged

sserrata merged 10 commits into
mainfrom
feat/theme-ux-refresh

Conversation

@sserrata

@sserrata sserrata commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds an opt-in modern API page layout with a refreshed API explorer. The classic layout stays the default and is unchanged: sites that do not opt in render and behave exactly as on main, with no config change.

Modern layout (opt-in)

  • The right panel shows a Try it button, code samples, and a response example card with tabs for each status code (from spec examples, or generated from the schema).
  • The request form, live response, and history open in a Try it side panel. Escape or a backdrop click closes it, focus moves into it and returns on close, and Tab stays inside the panel. It renders through a portal so it shows above the navbar.
  • How to opt in (first match wins):
    1. Page front matter: api_layout: modern
    2. Per spec: plugin option apiLayout: "modern" (written into front matter)
    3. Site-wide: themeConfig.api.layout: "modern"
  • Modern-only visual style (classic stays as on main): compact pill-style language tabs, normal-case section and card headers, pill-style required/deprecated/nullable labels, monospace type labels, and lowercase monospace MIME tabs. The styles are scoped under .openapi-layout--modern and the Try it panel.
  • ApiLayoutContext (from @theme/ApiExplorer/useApiLayout) lets a site add a reader-facing switch. The demo uses it for a Classic | Modern switch in the navbar.

Explorer improvements (modern layout)

  • Removed the artificial 1.2 s delay before every request. Added a loading state, a disabled send button while loading, and a Ctrl/⌘+Enter shortcut.
  • The request status is now tracked in state. Before, the code compared against the translated "Fetching..." string, which broke in non-English locales.
  • Response status bar with status text, response time, and size. Request errors show in a distinct alert style.
  • Recent requests: the last 5 responses per page, kept in memory only (not persisted, because responses can contain credentials). The list clears when the reader leaves the page.
  • A Cancel button aborts a running request. Send and Try it show only when a request can be sent.
  • Endpoint bar: highlighted path params, copy-URL button, and a "Try it" button. Long paths wrap on narrow screens.
  • Bug fix: FormTextInput replaced react-hook-form's onChange, so field values updated only on blur.
  • Accessibility: focus rings, prefers-reduced-motion, a live region for responses, and higher-contrast send button and qualifier labels in dark mode.
  • Visible input borders.

Classic layout

The classic Request, Response, and endpoint bar keep the main code (Request/index.tsx, Response/index.tsx, the classic branch of MethodEndpoint), and all refreshed styles are scoped to :is(.openapi-layout--modern, .openapi-try-it). The only classic changes are two invisible safeguards: a second submit while a request runs is ignored, and a running request is aborted when the page unmounts.

Other new opt-in theme options

  • sidebarMethodBadges: sidebar HTTP method badges. The selectors use :where() (zero specificity), so existing site CSS always wins.
  • hideTableOfContents: hides the desktop TOC on API and schema pages.

All new options are documented in the plugin README.

Test plan

  • yarn test: 662/662 pass (new tests: request history, client modules, api_layout front matter for API and schema pages)
  • tsc --noEmit for plugin and theme
  • ESLint on changed package files; Prettier
  • Demo production build (docusaurus build)
  • Classic backward compatibility: built main and this branch with main's demo config (an upgrade with no config change). Desktop, mobile, and dark mode screenshots show 0 different pixels, the page HTML is identical, and the explorer send flow gives identical panel HTML on API, webhook, schema, info, and /tests/ pages.
  • Headless Chromium checks: light, dark, and mobile; send request; Ctrl+Enter; history clears after the reader leaves the page; Try it panel focus, Escape, and focus return; Classic/Modern switch persists after reload; no page errors

Note: yarn lint fails on main too, because of the cypress/globals ESLint environment. It is not related to this PR.

🤖 Generated with Claude Code

Add a "modern" API page layout, opt-in at three levels: page front matter
(api_layout), per spec (plugin option apiLayout), or site-wide
(themeConfig.api.layout). The modern layout shows code samples and response
examples in the right panel and opens the request form in a "Try it" side
panel. The classic layout remains the default.

Explorer changes for both layouts:
- Remove the artificial 1.2 s request delay; add loading state, disabled
  send button and Ctrl/Cmd+Enter shortcut
- Track request status explicitly instead of comparing against the
  translated "Fetching..." string (broke in non-English locales)
- Show status text, response time and size; style request errors
- Keep the last five responses per endpoint in memory (not persisted)
- Endpoint bar: highlighted path params, copy URL button, "Try it" link
- Fix FormTextInput overriding react-hook-form's onChange, which left
  values stale until blur
- Accessibility: focus rings, reduced-motion support, live region,
  higher-contrast button and qualifier labels in dark mode
- Visual polish: compact language tabs, visible input borders, pill
  qualifiers, less uppercase text

New opt-in theme options: sidebarMethodBadges and hideTableOfContents.
The demo gains a Classic/Modern switch in the navbar.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Size Change: +35.9 kB (+1.47%)

Total Size: 2.48 MB

📦 View Changed
Filename Size Change
demo/.docusaurus/docusaurus.config.mjs 16.8 kB +162 B (+0.98%)
demo/build/assets/css/styles.********.css 240 kB +22.7 kB (+10.44%) ⚠️
demo/build/assets/js/main.********.js 734 kB +2.18 kB (+0.3%)
demo/build/index.html 100 kB +293 B (+0.29%)
demo/build/petstore/add-pet/index.html 30.3 kB +293 B (+0.98%)
demo/build/petstore/create-user/index.html 24.9 kB +293 B (+1.19%)
demo/build/petstore/create-users-with-array-input/index.html 25 kB +293 B (+1.19%)
demo/build/petstore/create-users-with-list-input/index.html 25 kB +293 B (+1.19%)
demo/build/petstore/delete-order/index.html 24.9 kB +293 B (+1.19%)
demo/build/petstore/delete-pet/index.html 25.1 kB +293 B (+1.18%)
demo/build/petstore/delete-user/index.html 25.2 kB +293 B (+1.17%)
demo/build/petstore/find-pets-by-status/index.html 25.7 kB +293 B (+1.15%)
demo/build/petstore/find-pets-by-tags/index.html 26.4 kB +293 B (+1.12%)
demo/build/petstore/get-inventory/index.html 24.1 kB +293 B (+1.23%)
demo/build/petstore/get-order-by-id/index.html 25.1 kB +293 B (+1.18%)
demo/build/petstore/get-pet-by-id/index.html 25.8 kB +293 B (+1.15%)
demo/build/petstore/get-user-by-name/index.html 25.3 kB +293 B (+1.17%)
demo/build/petstore/login-user/index.html 25.9 kB +293 B (+1.15%)
demo/build/petstore/logout-user/index.html 24.6 kB +293 B (+1.21%)
demo/build/petstore/new-pet/index.html 25.2 kB +293 B (+1.17%)
demo/build/petstore/pet/index.html 23.5 kB +293 B (+1.26%)
demo/build/petstore/place-order/index.html 24.4 kB +293 B (+1.22%)
demo/build/petstore/schemas/apiresponse/index.html 25.6 kB +293 B (+1.16%)
demo/build/petstore/schemas/cat/index.html 39.6 kB +293 B (+0.75%)
demo/build/petstore/schemas/category/index.html 26.7 kB +293 B (+1.11%)
demo/build/petstore/schemas/dog/index.html 40 kB +293 B (+0.74%)
demo/build/petstore/schemas/honeybee/index.html 40 kB +293 B (+0.74%)
demo/build/petstore/schemas/id/index.html 23.8 kB +293 B (+1.25%)
demo/build/petstore/schemas/order/index.html 27.8 kB +293 B (+1.07%)
demo/build/petstore/schemas/pet/index.html 39.6 kB +293 B (+0.75%)
demo/build/petstore/schemas/tag/index.html 25.1 kB +293 B (+1.18%)
demo/build/petstore/schemas/user/index.html 41.5 kB +293 B (+0.71%)
demo/build/petstore/store/index.html 22.5 kB +293 B (+1.32%)
demo/build/petstore/subscribe-to-the-store-events/index.html 31.2 kB +293 B (+0.95%)
demo/build/petstore/swagger-petstore-yaml/index.html 31.4 kB +293 B (+0.94%)
demo/build/petstore/update-pet-with-form/index.html 25.2 kB +293 B (+1.17%)
demo/build/petstore/update-pet/index.html 25.6 kB +293 B (+1.16%)
demo/build/petstore/update-user/index.html 25.2 kB +293 B (+1.18%)
demo/build/petstore/upload-file/index.html 25.1 kB +293 B (+1.18%)
demo/build/petstore/user/index.html 23.1 kB +293 B (+1.28%)
ℹ️ View Unchanged
Filename Size Change
demo/.docusaurus/codeTranslations.json 2 B 0 B
demo/.docusaurus/globalData.json 83.8 kB 0 B
demo/.docusaurus/i18n.json 372 B 0 B
demo/.docusaurus/registry.js 121 kB 0 B
demo/.docusaurus/routes.js 115 kB 0 B
demo/.docusaurus/routesChunkNames.json 47.7 kB 0 B
demo/.docusaurus/site-metadata.json 1.58 kB 0 B
demo/build/assets/js/runtime~main.********.js 27.3 kB -15 B (-0.05%)

compressed-size-action

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit 2cac646):

https://docusaurus-openapi-36b86--pr1709-kb4mjo3b.web.app

(expires Mon, 16 Nov 2026 19:09:55 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: bf293780ee827f578864d92193b8c2866acd459f

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

📸 Visual Diff Report

Snapshot comparison against https://docusaurus-openapi.tryingpan.dev/

Total ✅ Match ❌ Diff ⏭ Skip
228 228 0 0

✅ No visual regressions detected.

Updated at 2026-11-09T19:15:37.611Z · run 42680165340

Restore the original icon-card language tabs in the classic layout so the
two layouts stay distinct. The compact pill tabs now apply only inside
the modern layout wrapper (.openapi-explorer--modern).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
sserrata and others added 2 commits November 5, 2026 11:30
Keep the classic layout visually identical to main for section headers,
explorer card headers, required/deprecated/nullable labels, schema type
labels, and MIME/schema tabs. The polished variants now apply only under
.openapi-layout--modern (added by ApiItem/Layout) and inside the Try it
panel.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
- Show Send and "Try it" only when a request can be sent (shared
  useCanSendRequest hook), and apply the same rule to Ctrl/Cmd+Enter.
- Guard against double submits for the whole request, including event
  streams, and add a Cancel button that aborts the request.
- Trim the trailing slash of the server URL, and report clipboard
  failures through a shared copyToClipboard helper.
- Add api_layout front matter to schema pages.
- Show the page's api_layout in the demo layout picker.
- Clear the request history when the page that shows it unmounts.
- Share colorForMethod, renderPath and statusTone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
sserrata and others added 3 commits November 9, 2026 11:57
The explorer refresh now applies only to the opt-in modern layout.
Sites that do not set `layout: "modern"` render and behave as before.

- Restore the classic Request, Response and MethodEndpoint from main,
  and move the refreshed versions to Request/Modern, Response/Modern
  and MethodEndpoint/Modern. The Try it drawer uses the modern ones,
  and MethodEndpoint selects by layout.
- Scope the refreshed styles (endpoint bar, request and response
  panels, form fields, input and code font sizes, dark-mode qualifier
  colors) to `:is(.openapi-layout--modern, .openapi-try-it)`.
- Keep the classic FormTextInput change handling and CopyButton as on
  main.
- Classic Request keeps two invisible safeguards: it ignores a second
  submit while a request runs, and aborts the request on unmount.
- useApiLayout returns the default outside a doc page, so
  MethodEndpoint still works on standalone pages.
- Modern layout: wrap long endpoint paths on narrow screens instead of
  cutting them off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This reverts commit cb6612b.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@sserrata
sserrata merged commit 0235e90 into main Nov 9, 2026
12 checks passed
@sserrata
sserrata deleted the feat/theme-ux-refresh branch November 9, 2026 19:21
sserrata added a commit to tmeghe/docusaurus-openapi-docs that referenced this pull request Nov 20, 2026
Resolve yarn.lock conflict and mock the modern MethodEndpoint layout
in the QUERY badge test after PaloAltoNetworks#1709.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

This branch was successfully deployed

1 active deployment
preview — 2cac6463 Deployed Nov 9, 2026 by sserrata via Delete preview channels #3
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.

1 participant