Fix API docs sidebar not expanding on client-side navigation - #900
Conversation
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/*.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe ChangesIPA redirect handling
Estimated code review effort: 2 (Simple) | ~5 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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
next.config.mjsOops! Something went wrong! :( ESLint: 9.39.2 TypeError: Converting circular structure to JSON 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. Comment |
* 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.
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 toundefined - 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 receivedpageProps, which carries bothsections(the method list the sidebar expands from) andtitle. A full reload worked because statically generated HTML has the props inlined.Fix
Add a
missingcondition on thex-nextjs-dataheader 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/*./ipa/resources/networksnow returns 200 with fullpageProps(title and all method sections)/ipa/resources/networksstill returns 308 →/api/resources/networksSummary by CodeRabbit
/ipato/api.