Next.js Cache Components: navigating between params of a root layout hides <html> and throws HierarchyRequestError (blank page)
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 48/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Stack de tecnologia
- next.js, react, typescript
- Domínio
- frontend
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- TypeScript
- Estrelas
- 640
- Forks
- 32
- Merge médio
- 1h 15min
- PRs com merge (30d)
- 7
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de TanStack/redact
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
TanStack/redact#195 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
TanStack/redact#142 · 4 comentários ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 1 dia
Todas as issues de TanStack/redact
Issues semelhantes
-
bug data-types
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
ClickHouse/clickhouse-js#1293 ·
Mantenedores costumam responder em até 1 dia
-
area: middleware enhancement good first issue
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
-
agent/quality testing
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 95/100
Mantenedores costumam responder em até 1 dia
-
GitHub registry install via `gh` credentials rewrites `\u0000`–`\u001f` escapes in source files to `^@`–`^_`Talvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 92/100
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
juspay/agent-distro#203 ·
Mantenedores costumam responder em até 1 dia