Flight chunks read with `use()` are thrown instead of read, and Next.js hydration replaces the server DOM

Offen
#89 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@mamal72 arbeitet bereits daran.

Seit 27.10.2026.

  • #90 von @mamal72 — offen

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Veraltet
Bereich
frontend, testing

Rechercherichtung

Read src/react/thenable.ts and compare its handling of unsettled chunks with the trackUsedThenable behavior described in the issue. Reproduce using the examples/next-demo production build with and without NEXT_TEST_REFERENCE=1; verify that the server-rendered paragraph remains during hydration and no mismatch is reported. Related issue #82 covers genuinely pending promises.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Version: @tanstack/redact 0.2.1 via withRedact, Next.js 16.4.3 (App Router, Turbopack, production), react/react-dom 19.3.1, Chromium. Unchanged on main (20f6dd6).

What happens

A Server Component passes a promise to a Client Component, which reads it with use(). During hydration, Redact reports Hydration mismatch. and replaces the server-rendered element, even though the content matches. React 19.3.1 hydrates the same page with no errors and keeps the server node.

Repro

// app/flight-promise/page.jsx
import Reader from './reader'
export default function Page() {
  return <main><Reader value={Promise.resolve('Read from the server')} /></main>
}

// app/flight-promise/reader.jsx
'use client'
import { use } from 'react'
export default function Reader({ value }) {
  return <p id="read">{use(value)}</p>
}

Comparing the same page in examples/next-demo (next build && next start, with and without NEXT_TEST_REFERENCE=1):

React 19.3.1 Redact 0.2.1
Server <p id="read"> kept yes no, replaced
pageerror none Hydration mismatch.

Impact

In a larger App Router app, the same promises are also thrown as bare values ({status: "resolved_model", value: null} and {status: "blocked", …}) instead of being read. Client interactions in the affected tree stop working, including dialogs opened from search params, search and locale switching.

Where

src/react/thenable.ts subscribes only when status === undefined. React's Flight client gives its chunks a status of their own (resolved_model, blocked, …), and they only initialize or settle once something calls .then(). React's trackUsedThenable subscribes to any unsettled thenable and then checks again, so a resolved_model chunk is read in the same pass. Redact throws it instead.

Related: #82. Once Redact suspends on such a chunk during hydration without a <Suspense> directly above it, the mismatch comes from the path described there. The PR for this issue avoids suspending on chunks that are already resolved, as React does; #82 still applies to promises that are really pending.

Vorherrschende Sprache
TypeScript
Sterne
640
Forks
32
Ø Merge
1 Std. 15 Min.
Gemergte PRs (30 T.)
7

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus TanStack/redact

Alle Issues in TanStack/redact

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.