Skip to content

Fix API docs sidebar not expanding on client-side navigation - #900

Merged
SunsetDrifter merged 1 commit into
mainfrom
docs/fix-api-nav-client-side-props
Aug 3, 2026
Merged

Fix API docs sidebar not expanding on client-side navigation#900
SunsetDrifter merged 1 commit into
mainfrom
docs/fix-api-nav-client-side-props

Conversation

@SunsetDrifter

@SunsetDrifter SunsetDrifter commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Problem

Navigating to an API resource page (e.g. /api/resources/networks) via a link left the sidebar method list collapsed and set the browser tab title to undefined - NetBird API. Both fixed themselves only after a full page reload.

Cause

On client-side navigation, Next.js fetches the target page's props from /_next/data/<buildId>/ipa/.... Next matches these data URLs against redirects using the page path, so the canonical-URL redirect /ipa/:path*/api/:path* answered the props fetch with a 308 instead of JSON. The router never received pageProps, which carries both sections (the method list the sidebar expands from) and title. A full reload worked because statically generated HTML has the props inlined.

Fix

Add a missing condition on the x-nextjs-data header to that redirect. The router's props fetch always sends this header, so data requests now bypass the redirect and return JSON; plain browser visits to /ipa/* don't send it and still get the canonical 308 to /api/*.

  • Props fetch for /ipa/resources/networks now returns 200 with full pageProps (title and all method sections)
  • Direct request to /ipa/resources/networks still returns 308 → /api/resources/networks

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where Next.js client-side data requests could be incorrectly redirected from /ipa to /api.
    • Existing permanent redirects remain unchanged for other requests.

The /ipa/:path* -> /api/:path* redirect also matched Next.js data
requests (/_next/data/.../ipa/...), returning a 308 instead of page
props. Client-side navigations to API pages therefore lost pageProps,
leaving the sidebar method list collapsed and the tab title undefined
until a full reload. Skip the redirect when the x-nextjs-data header is
present so props fetches go through; browser visits to /ipa/* still get
the canonical redirect to /api/*.
@vercel

vercel Bot commented Aug 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview Aug 3, 2026 9:02am

Request Review

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b0e4580a-e415-4c62-8f39-4dfcf5802c9c

📥 Commits

Reviewing files that changed from the base of the PR and between 63677de and 25a076d.

📒 Files selected for processing (1)
  • next.config.mjs

📝 Walkthrough

Walkthrough

The /ipa/:path* permanent redirect to /api/:path* now excludes requests that contain the x-nextjs-data header.

Changes

IPA redirect handling

Layer / File(s) Summary
Redirect condition update
next.config.mjs
The permanent /ipa/:path* redirect now applies only when the x-nextjs-data request header is absent.

Estimated code review effort: 2 (Simple) | ~5 minutes

Poem

A rabbit checked the redirect gate,
And kept data requests in their state.
IPA hops when headers are clear,
While Next.js data stays near.
Clean paths now bound through the gate.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the user-facing API documentation sidebar issue addressed by the redirect change during client-side navigation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/fix-api-nav-client-side-props

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

next.config.mjs

Oops! Something went wrong! :(

ESLint: 9.39.2

TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Object'
| property 'configs' -> object with constructor 'Object'
| property 'flat' -> object with constructor 'Object'
| ...
| property 'plugins' -> object with constructor 'Object'
--- property 'react' closes the circle
Referenced from:
at JSON.stringify ()
at file:///node_modules/@eslint/eslintrc/lib/shared/config-validator.js:308:45
at Array.map ()
at ConfigValidator.formatErrors (file:///node_modules/@eslint/eslintrc/lib/shared/config-validator.js:299:23)
at ConfigValidator.validateConfigSchema (file:///node_modules/@eslint/eslintrc/lib/shared/config-validator.js:330:84)
at ConfigArrayFactory._normalizeConfigData (file:///node_modules/@eslint/eslintrc/lib/config-array-factory.js:676:19)
at ConfigArrayFactory._loadConfigData (file:///node_modules/@eslint/eslintrc/lib/config-array-factory.js:641:21)
at ConfigArrayFactory._loadExtendedShareableConfig (file:///node_modules/@eslint/eslintrc/lib/config-array-factory.js:946:21)
at ConfigArrayFactory._loadExtends (file:///node_modules/@eslint/eslintrc/lib/config-array-factory.js:814:25)
at ConfigArrayFactory._normalizeObjectConfigDataBody (file:///node_modules/@eslint/eslintrc/lib/config-array-factory.js:752:25)


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@SunsetDrifter
SunsetDrifter merged commit e5da16c into main Aug 3, 2026
6 checks passed
@SunsetDrifter
SunsetDrifter deleted the docs/fix-api-nav-client-side-props branch August 3, 2026 10:16
SunsetDrifter added a commit that referenced this pull request Aug 3, 2026
* fix: serve props JSON for /api data requests via middleware rewrite

The /api/:path* -> /ipa/:path* rewrite in next.config.mjs is applied by
Vercel's routing to client-side props fetches
(/_next/data/<buildId>/api/....json), but the data-request context is
lost and the prerendered page HTML is returned instead of JSON
(vercel/next.js#39669). The router then never receives pageProps, so the
API sidebar stays collapsed and the tab title shows undefined until a
full reload. This half of the bug only occurs on Vercel infrastructure;
the dev server and next start resolve rewrites for data requests
correctly, and #900 fixed only the /ipa redirect half.

Middleware rewrites preserve data-request semantics, so rewrite /api/*
to /ipa/* in middleware for data requests only (x-nextjs-data header).
Regular page requests fall through to the existing config rewrites, and
the /ipa -> /api canonical redirect is unchanged.

* fix: move /api data-request rewrite into existing proxy.js

Next 16 uses proxy.js and rejects builds where both middleware.js and
proxy.js exist; this repo already had src/proxy.js for the
/docs-static/_next asset rewrite. Fold the /api -> /ipa data-request
rewrite into it and drop middleware.js. Verified the proxy intercepts:
data responses now carry x-middleware-rewrite: /ipa/... and JSON bodies.

* fix: map bare api.json data requests to ipa/introduction.json

The raw data-path fallback rewrote /_next/data/<build>/api.json to
/_next/data/<build>/ipa.json, but there is no /ipa index page; mirror
the /api -> /ipa/introduction rewrite instead.
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.

2 participants