Next.js Cache Components: navigating between params of a root layout hides <html> and throws HierarchyRequestError (blank page)
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 48/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- next.js, react, typescript
- Domaine
- frontend
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- TypeScript
- Étoiles
- 640
- Forks
- 32
- Merge moyen
- 1 h 15 min
- PR mergées (30 j)
- 7
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de TanStack/redact
-
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
TanStack/redact#195 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
TanStack/redact#142 · 4 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de TanStack/redact
Issues similaires
-
bug data-types
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
ClickHouse/clickhouse-js#1293 ·
Les mainteneurs répondent en général sous 1 jour
-
area: middleware enhancement good first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
-
agent/quality testing
Difficulté 1/5 Moins d'une heure Accessibilité débutants 95/100
Les mainteneurs répondent en général sous 1 jour
-
GitHub registry install via `gh` credentials rewrites `\u0000`–`\u001f` escapes in source files to `^@`–`^_`Peut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 92/100
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
juspay/agent-distro#203 ·
Les mainteneurs répondent en général sous 1 jour