From a5eaff8d357c3af59850a0e9c10a74b45826d1fb Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 12 Oct 2026 10:26:55 +0000 Subject: [PATCH 1/2] fix(docs): match the nav against the public path, so Blog and Why light on a blog post Posts prerender under app/[lang]/ at /en/blog/SLUG, and Next's usePathname() answers that internal path during the prerender while every nav link (and the docs page tree) is public. The browser-side pathname is already public, so hydration read a match the server HTML never rendered and React kept the server's data-active=false. The root provider is now fumadocs' NextProvider composition with usePathname mapped through toPublicPath() (the hidden default-locale prefix removed, the proxy's own /en redirect mapping), so the prerender agrees with hydration. Claude-Session: https://claude.ai/code/session_012yK1ddAdAqfzwigRHZq3r2 Co-authored-by: Claude --- apps/docs/app/[lang]/layout.tsx | 2 +- apps/docs/components/root-provider.tsx | 43 ++++++++++++++++++++++++++ apps/docs/lib/i18n.ts | 21 +++++++++++++ apps/docs/lib/layout.shared.tsx | 2 ++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 apps/docs/components/root-provider.tsx diff --git a/apps/docs/app/[lang]/layout.tsx b/apps/docs/app/[lang]/layout.tsx index 9202a8f2568..636573eeeb5 100644 --- a/apps/docs/app/[lang]/layout.tsx +++ b/apps/docs/app/[lang]/layout.tsx @@ -1,5 +1,5 @@ import type { ReactNode } from 'react'; -import { RootProvider } from 'fumadocs-ui/provider/next'; +import { RootProvider } from '@/components/root-provider'; import { notFound } from 'next/navigation'; import { i18n, isSupportedLanguage } from '@/lib/i18n'; diff --git a/apps/docs/components/root-provider.tsx b/apps/docs/components/root-provider.tsx new file mode 100644 index 00000000000..c72585d3320 --- /dev/null +++ b/apps/docs/components/root-provider.tsx @@ -0,0 +1,43 @@ +'use client'; + +import { FrameworkProvider } from 'fumadocs-core/framework'; +import { RootProvider as BaseRootProvider, type RootProviderProps } from 'fumadocs-ui/provider/base'; +import Image from 'next/image'; +import Link from 'next/link'; +import { useParams, usePathname, useRouter } from 'next/navigation'; +import { toPublicPath } from '@/lib/i18n'; + +/** Next's pathname, as the visitor's URL spells it — see `toPublicPath()`. */ +function usePublicPathname(): string { + return toPublicPath(usePathname()); +} + +/** + * `fumadocs-ui/provider/next`'s `RootProvider`, with one difference: the + * pathname every fumadocs component reads is the PUBLIC path. + * + * That provider is `NextProvider` (Next's hooks, `next/link`, `next/image`) + * around the base `RootProvider`; this is the same composition with + * `usePathname` swapped for `usePublicPathname`. Without it, a page prerendered + * under `app/[lang]/` renders its nav and sidebar against `/en/...` while every + * link they match is public, so the top nav's `Blog` (nested-url) and `Why` + * (url) entries never lit on a blog post, and the docs sidebar's current page + * was unmarked in the server HTML. + * + * In the browser Next already answers the public path — `proxy.ts` redirects + * any `/en/...` URL away — so the mapping changes nothing there; it only makes + * the prerender agree with what hydration reads. + */ +export function RootProvider(props: RootProviderProps) { + return ( + + + + ); +} diff --git a/apps/docs/lib/i18n.ts b/apps/docs/lib/i18n.ts index ae20a3c32da..bd25f5acb36 100644 --- a/apps/docs/lib/i18n.ts +++ b/apps/docs/lib/i18n.ts @@ -30,3 +30,24 @@ export const i18n = defineI18n({ export function isSupportedLanguage(value: string): boolean { return (i18n.languages as readonly string[]).includes(value); } + +/** + * The public URL path for a route path: the hidden default-locale prefix + * removed (`/en/blog/x` → `/blog/x`, `/en` → `/`); any other path unchanged. + * + * Every page lives under `app/[lang]/`, so a page prerendered at build time is + * rendered at its internal path — `/en/blog/x` — and that is what Next's + * `usePathname()` answers during the prerender. A visitor never sees that path: + * `proxy.ts` rewrites `/blog/x` to it and redirects `/en/...` away, and the + * browser-side `usePathname()` answers the public `/blog/x`. Every URL fumadocs + * compares a pathname against (nav links, the docs page tree) is public too, so + * the server-side comparison missed on every prerendered page and hydration + * never repainted the result. This is the same mapping as the proxy's + * `/en/...` redirect, read from the same config. + */ +export function toPublicPath(pathname: string): string { + if (i18n.hideLocale !== 'default-locale') return pathname; + const prefix = `/${i18n.defaultLanguage}`; + if (pathname === prefix) return '/'; + return pathname.startsWith(`${prefix}/`) ? pathname.slice(prefix.length) : pathname; +} diff --git a/apps/docs/lib/layout.shared.tsx b/apps/docs/lib/layout.shared.tsx index aef28da53d3..a5cca6b1b9d 100644 --- a/apps/docs/lib/layout.shared.tsx +++ b/apps/docs/lib/layout.shared.tsx @@ -28,6 +28,8 @@ export function baseOptions(): BaseLayoutProps { }, // Every layout spreads baseOptions() — DocsLayout (docs sidebar), and HomeLayout on // the home page and on /blog — so these entries are the nav's links on all of them. + // `active` is matched against the PUBLIC pathname (`/blog/x`, never the `/en/blog/x` + // a post is prerendered under) — `components/root-provider.tsx` supplies it. links: [ { text: 'Why', url: ESSAY_URL, active: 'url' }, { text: 'Blog', url: '/blog', active: 'nested-url' }, From 7324c3cb287fe44424c6dced804a840b3f65d203 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 12 Oct 2026 10:32:13 +0000 Subject: [PATCH 2/2] fix(docs): type the provider's Link and Image as fumadocs' framework props Claude-Session: https://claude.ai/code/session_012yK1ddAdAqfzwigRHZq3r2 Co-authored-by: Claude --- apps/docs/components/root-provider.tsx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/apps/docs/components/root-provider.tsx b/apps/docs/components/root-provider.tsx index c72585d3320..d01857ec54f 100644 --- a/apps/docs/components/root-provider.tsx +++ b/apps/docs/components/root-provider.tsx @@ -1,6 +1,6 @@ 'use client'; -import { FrameworkProvider } from 'fumadocs-core/framework'; +import { type Framework, FrameworkProvider } from 'fumadocs-core/framework'; import { RootProvider as BaseRootProvider, type RootProviderProps } from 'fumadocs-ui/provider/base'; import Image from 'next/image'; import Link from 'next/link'; @@ -18,11 +18,14 @@ function usePublicPathname(): string { * * That provider is `NextProvider` (Next's hooks, `next/link`, `next/image`) * around the base `RootProvider`; this is the same composition with - * `usePathname` swapped for `usePublicPathname`. Without it, a page prerendered - * under `app/[lang]/` renders its nav and sidebar against `/en/...` while every - * link they match is public, so the top nav's `Blog` (nested-url) and `Why` - * (url) entries never lit on a blog post, and the docs sidebar's current page - * was unmarked in the server HTML. + * `usePathname` swapped for `usePublicPathname`. (The two casts: Next's + * `href`/`src` are required where fumadocs' prop types leave them optional; + * `NextProvider` hands these same two components to these same props.) + * + * Without it, a page prerendered under `app/[lang]/` renders its nav and sidebar + * against `/en/...` while every link they match is public, so the top nav's + * `Blog` (nested-url) and `Why` (url) entries never lit on a blog post, and the + * docs sidebar's current page was unmarked in the server HTML. * * In the browser Next already answers the public path — `proxy.ts` redirects * any `/en/...` URL away — so the mapping changes nothing there; it only makes @@ -34,8 +37,8 @@ export function RootProvider(props: RootProviderProps) { usePathname={usePublicPathname} useRouter={useRouter} useParams={useParams} - Link={Link} - Image={Image} + Link={Link as Framework['Link']} + Image={Image as Framework['Image']} >