Repository navigation
frontend(fix): give Fumadocs the public pathname so docs pages hydrate - #585
Conversation
Every docs page threw minified React #418 (server-rendered text did not match the client) in production. Docs pages are prerendered at their internal route (/en/docs/...) and served at the public URL (/docs/...). fumadocs-ui/provider/next hands Fumadocs next/navigation's pathname, which reads /en/docs while prerendering and /docs in the browser. Fumadocs matches its chrome against that pathname, so the static HTML missed the page tree: the mobile TOC trigger said "On this page" where the client rendered the page title, and the prev/next footer and breadcrumb were missing. pnpm dev renders on request at the public URL, so it never reproduced. publicPathname() maps a route pathname to the URL the browser shows, and FumadocsRootProvider wires Fumadocs to Next.js like the stock provider except for that pathname. The docs and blog layouts use it. The blog had no pathname-derived chrome, but it sat on the same stock provider. The new frontend e2e check fails on the unfixed production build with the #418 error and passes with the fix. The int spec covers publicPathname and rejects stock-provider imports. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Repository guideline files applied to this review (1)No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: Ducksss/payload-components/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (6)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe docs and blog layouts now use a local Fumadocs provider. It integrates Next.js components and navigation, and supplies Fumadocs with a public localized pathname. Tests cover pathname handling, provider wiring, and docs-route page errors. ChangesFumadocs provider integration
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~15 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to This change fixes the reported docs hydration mismatch by giving Fumadocs the public pathname. No concrete merge-blocking risk was found in the supplied changes. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The inspected change is limited to how documentation and blog UI interpret localized URLs. No new privileged action or access-control bypass was identified. Risk remains low rather than minimal because the third-party provider’s internal behavior could not be independently verified. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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 |
Summary
Every Fumadocs docs page threw a React hydration error in production:
Minified React error #418 … args[]=text, meaning the server-rendered text didn't match the client./and the non-docs routes were unaffected.Root cause
Docs pages are statically prerendered at their internal route,
/en/docs/...(the[locale]segment). The proxy serves them at the public URL,/docs/....fumadocs-ui/provider/nexthands Fumadocsnext/navigation's rawusePathname(), and that reads differently on each side:usePathname()next build)/en/docs["","en","docs"]/docspnpm dev(rendered per request)/docs["","docs"]Fumadocs matches its chrome against that pathname:
TreeContextProvider→searchPath(tree, pathname). In the static HTML nothing matched, so the mobile TOC trigger (PageTOCPopoverTrigger,path?.name ?? t('On this page')) rendered "On this page" while the client rendered the page title ("Introduction" on/docs). That is the mismatched text node. The same miss also left the prev/next footer and breadcrumb out of the static HTML. Dev renders at the public URL, so it never reproduced there.I found the node by diffing the server HTML's text nodes (JS disabled) against the hydrated DOM on the live site.
Fix
publicPathname()insrc/i18n/config.tsmaps a route pathname to the URL the browser shows (/en/docs→/docs;/zh/docsis unchanged). It is built on the existingsplitLocalePathname/localizeHref.FumadocsRootProvider(src/components/site/FumadocsRootProvider.tsx) wires Fumadocs'RootProviderto Next.js the wayfumadocs-ui/provider/nextdoes, except thatusePathnamereturnspublicPathname(usePathname()). Client behavior is unchanged, because the browser pathname is already public. The static HTML now matches it.No
suppressHydrationWarning: nothing here is time-dependent.Tests
hydrates docs pages without React errors(tests/e2e/frontend.e2e.spec.ts) loads/docs,/docs/installation,/docs/components/hero-basicand/docs/design, then asserts nopageerroronce the root has hydrated. Against a production build of the unfixed layouts it fails with the exact#418 … args[]=texterror; with the fix it passes. It only bites in production mode, which is what CI'stest:ciruns.tests/int/site-i18n.int.spec.ts) covers thepublicPathnamecases, checks that nothing insrc/importsfumadocs-ui/provider/next, and checks that both Fumadocs layouts use the site provider. It also fails on the unfixed layouts.Validation (local, macOS)
pnpm lint✅ ·pnpm exec tsc --noEmit✅ ·pnpm format:check✅pnpm run test:int✅ 64 files, 795 tests passed (the env-gated pack spec skipped)pnpm build:e2e && PLAYWRIGHT_SERVER_MODE=production pnpm test:e2e frontend✅ 154 passed, 1 skipped (the Linux-only visual baseline)pageerroron/docs,/docs/installation,/docs/components/hero-basic,/docs/design,/docs/changelog,/docs/architecture, a blog post, or/. On the live site,/docs,/docs/installation,/docs/components/hero-basic,/docs/designand/docs/changelogall throw#418today.🤖 Generated with Claude Code
Summary by CodeRabbit