Next.js Cache Components: navigating between params of a root layout hides <html> and throws HierarchyRequestError (blank page)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- next.js, react, typescript
- Área
- frontend
Línea de trabajo
Start with src/dom/reconcile.ts at placeDomsInOrder (around line 474), then trace the placement path through commitPlacements and the view transition handling in src/dom/features/view-transition/full.ts. Reproduce with the provided Next.js app using Cache Components and navigate from /it to /en; compare with native React. Done means both router.push and <Link> navigate without a HierarchyRequestError or hiding the document.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Version: @tanstack/redact 0.2.2 (latest on npm) through withRedact, Next.js 16.4.3 (App Router, Turbopack), react/react-dom 19.3.1, Chromium, production build (next build && next start) and next dev.
What happens
With cacheComponents: true, the root layout lives under a dynamic segment (app/[lang]/layout.js renders <html lang={lang}>). A client navigation from /it to /en (router.push or <Link>) leaves a blank page:
HierarchyRequestError: Failed to execute 'insertBefore' on 'Node': Only one element on document allowed.is thrown.<html>getsstyle="display: none !important;", so the whole document is hidden.- The URL stays
/it, while<html lang>becomesen.
Native React hydrates the same app and navigates with no error. It keeps the single <html>, hides only the outgoing route's <main> with display: none !important, and inserts the new <main> into the same <body>.
After clicking router.push('/en') on /it |
React 19.3.1 | Redact 0.2.2 |
|---|---|---|
location.pathname |
/en |
/it |
<html lang> |
en |
en |
<html style> |
none | display: none !important; |
Outgoing <main> ("Ciao") |
display: none !important |
still in <body>, the document is hidden |
| Page errors | 0 | 1 (HierarchyRequestError) |
| What you see | "Hello" | blank page |
The same table holds for <Link href="/en">. With cacheComponents: false, Redact navigates correctly, like React. So the trigger seems to be the outgoing root layout being kept hidden (Activity) while the incoming one mounts its own <html>: the hide is applied to the <html> singleton itself, and the new <html> is placed as a second document element.
Reproduction
package.json dependencies: [email protected], [email protected], [email protected], @tanstack/[email protected].
next.config.mjs:
import { withRedact } from '@tanstack/redact/next'
const config = {
cacheComponents: process.env.CACHE_COMPONENTS !== '0',
}
export default process.env.REDACT === '1' ? withRedact(config) : config
app/[lang]/layout.js:
export function generateStaticParams() {
return [{ lang: 'en' }, { lang: 'it' }]
}
export default async function RootLayout({ children, params }) {
const { lang } = await params
return (
<html lang={lang}>
<body>{children}</body>
</html>
)
}
app/[lang]/page.js:
import { Switcher } from './switcher'
export default async function Page({ params }) {
const { lang } = await params
return (
<main>
<h1>{lang === 'it' ? 'Ciao' : 'Hello'}</h1>
<Switcher lang={lang} />
</main>
)
}
app/[lang]/switcher.js:
'use client'
import Link from 'next/link'
import { useRouter } from 'next/navigation'
export function Switcher({ lang }) {
const router = useRouter()
const other = lang === 'it' ? 'en' : 'it'
return (
<p>
<button id="push" onClick={() => router.push(`/${other}`)}>
router.push(/{other})
</button>{' '}
<Link id="link" href={`/${other}`}>
Link to /{other}
</Link>
</p>
)
}
Steps:
REDACT=1 next build && REDACT=1 next start- Open
/it, wait for hydration, click the button (or the link). - The page goes blank and the error above is thrown.
Results across the four builds (production, Chromium, each run checked twice: router.push and <Link>):
| Build | Navigation /it → /en |
|---|---|
React, cacheComponents: true |
works |
Redact, cacheComponents: true |
blank page, HierarchyRequestError |
React, cacheComponents: false |
works |
Redact, cacheComponents: false |
works |
Stack (development, next dev)
HierarchyRequestError: Failed to execute 'insertBefore' on 'Node': Only one element on document allowed.
at placeDomsInOrder (node_modules/@tanstack/redact/dist/…)
at commitPlacements
at commitMutation
at mutation
at within
at consume
at cancel
Mapped to source in a Vinext dev server (same package version):
> placeDomsInOrder src/dom/reconcile.ts:474:22
> commitPlacements src/dom/reconcile.ts:1203:8
> commitMutation src/dom/commit.ts:112:24
> mutation src/dom/features/view-transition/full.ts:91:36
> src/dom/features/view-transition/full.ts:74:4
> within src/dom/features/view-transition/full.ts:147:8
> consume src/dom/features/view-transition/full.ts:72:2
> cancel src/dom/features/view-transition/full.ts:63:4
> src/dom/features/view-transition/full.ts:234:8
Also seen with Vinext
We first hit this on a production landing site that builds with Vinext 1.3.0 and redact() from @tanstack/redact/vinext, with one root layout per locale and Cache Components on. The language picker (router.push) failed in 8 of 8 runs on vite build + vite preview and also failed in vite dev, while native React passed 8 of 8. That app uses @cloudflare/vite-plugin 2.0.0-beta, outside the Vinext matrix, so the Next.js reproduction above is the one to use.
A document navigation (window.location.assign) avoids the bug, at the cost of a full page load.
Not tested against main after the 0.2.2 release (#94 landed afterwards).
Found and reduced with Claude Code; every result above was run and checked against native React before filing.
- Lenguaje dominante
- TypeScript
- Estrellas
- 640
- Forks
- 32
- Merge medio
- 1 h 15 min
- PR fusionados (30 d)
- 7
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de TanStack/redact
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
TanStack/redact#195 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
TanStack/redact#142 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
Todos los issues de TanStack/redact
Issues similares
-
bug data-types
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
ClickHouse/clickhouse-js#1293 ·
Los mantenedores suelen responder en 1 día
-
area: middleware enhancement good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
agent/quality testing
Dificultad 1/5 Menos de una hora Aptitud para principiantes 95/100
Los mantenedores suelen responder en 1 día
-
GitHub registry install via `gh` credentials rewrites `\u0000`–`\u001f` escapes in source files to `^@`–`^_`Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 92/100
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
juspay/agent-distro#203 ·
Los mantenedores suelen responder en 1 día