Repository navigation
Description
Summary
For a client-routed (useCSR = True) project with a dynamic route such as src/routes/[lang]/..., the shell of that route is rendered with usePathname() returning the route pattern (/{lang}, /{lang}/about, /{lang}/work/{slug}) instead of a real path. Any link built from usePathname() is written into the served HTML with the placeholder in its href, for example /en/{lang}/about. React does not patch a mismatching href during hydration, so the wrong value stays after the page is interactive. Clicking such a link opens /en/%7Blang%7D/about.
Versions
- nexy 2.11.2 (Python), React 19.3.1, Vite 7.3.8, Node 22
- Project is client-rendered (
useCSR = True) withsrc/routes/[lang]/index.tsx,about.tsx,work/[slug].tsx
Steps to reproduce
-
Use a root layout that reads
usePathname()and builds a link from it, for example a language switch:const pathname = usePathname(); // "/fr/about" in the browser const page = pathname.replace(/^\/(fr|en)/, ""); <a href={`/en${page}`}>EN</a>
-
nx build, thennx start. -
Request the page and read the link:
$ curl -s http://localhost:3000/fr/about | grep -o 'href="/en[^"]*"' href="/en/{lang}/about" $ curl -s http://localhost:3000/fr/work/yano | grep -o 'href="/en[^"]*"' href="/en/{lang}/work/{slug}" -
Open the page in a browser, wait for hydration, then read the attribute again: it is still
/en/{lang}/about. Click it: the address becomes/en/%7Blang%7D/about.
Seen on a deployed site: https://luilka.vercel.app/en/%7Blang%7D after clicking the language switch on the home page.
Expected
During the render of a shell, usePathname() returns a real path, or the framework makes it clear that it returns a pattern. A link built from it should not ship with {lang} in its href.
Actual
usePathname() returns the pattern while the shell is rendered, and the served HTML carries it.
Where it comes from
In the generated __nexy__/document.ts, the shell of every dynamic route is rendered with the pattern as pathname, and no params:
// Every dynamic route keeps its shell: the server falls back to it for a path not listed.
const html = await renderDocument(server, null, route.layouts ?? [], {},
{ pathname: route.path, search: '' }) // route.path === "/{lang}/about"The routes that have static params get a real pathname through buildPathname(route, params); the fallback shell does not. A request such as /fr/about or /fr/work/yano is answered with this fallback shell, so the first HTML of every page under [lang] is built from the pattern.
Suggestions
- Render the fallback shell with a pathname that has no placeholder (for example the first static param set, or
/), or - Give
usePathname()an empty ornullvalue while a shell is rendered, so a component can skip the link until it is mounted, or - Re-render the document for the requested path instead of reusing a shell.
Workaround
Build the link after mount (useEffect plus state) and fall back to a placeholder-free address such as /en on the first render, so the server and the first client render match and the effect then writes the exact address.
Activity
github-actions commentedon Nov 28, 2026
Implemented by #699 and merged as 9e39f4a. Closing automatically.