renderToReadableStream streams a pending root boundary as fallback + script even after allReady, so react-email output is broken (0.3.1)

Ouverte
#182 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

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
42/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
nodejs, react, typescript
Domaine
backend, web-dev

Piste de recherche

Reproduce with the issue's script under NODE_ENV=production, rendering the same tree through react-dom/server and @tanstack/redact/server, and compare the HTML. Start at the renderToReadableStream server export and trace where suspense boundaries flush: the <!--$?0--> marker, $RC(0) script and hidden S:0 div must not appear once allReady resolves. Done means this repro emits one inline document matching React's output, with no fallback script or hidden segment.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Summary

When everything under the outermost Suspense boundary suspends, Redact's renderToReadableStream still sends that boundary's fallback, the boundary script and a hidden <div id="S:0"> holding the real content, even when the caller waits for allReady before reading. React writes the finished content inline once allReady has resolved.

This breaks every email rendered by react-email under Redact. Its render() wraps the email in <Suspense>, waits for allReady, then reads the stream as a static document. Its Tailwind component suspends while it compiles, so the whole email is pending when the shell flushes. The resulting HTML has a <script>, an empty <div id="B:0">, and the <!DOCTYPE>/<html> nested inside a hidden <div>. Mail clients run no scripts, and a sandboxed preview <iframe> without allow-scripts shows a blank page.

Reproduction
import { Suspense, use } from 'react'
import { renderToReadableStream } from 'react-dom/server'

const data = new Promise((resolve) => setTimeout(() => resolve('Body text'), 20))

function Document() {
  return (
    <html lang="en">
      <head>
        <meta charSet="utf-8" />
        <title>Hello</title>
      </head>
      <body>
        <p>{use(data)}</p>
      </body>
    </html>
  )
}

const stream = await renderToReadableStream(
  <Suspense>
    <Document />
  </Suspense>,
  { progressiveChunkSize: Number.POSITIVE_INFINITY },
)
await stream.allReady
console.log(await new Response(stream).text())

Run with Node 26, NODE_ENV=production, once with React's react-dom/server and once with @tanstack/redact/server.

React 19.3.1:

<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><title>Hello</title></head><body><!--$--><!--html--><!--head--><!--body--><p>Body text</p><!--/$--></body></html>

Redact 0.3.1 (boundary runtime script shortened):

<!--$?0--><div id="B:0"></div><!--/$--><script>(function(){ /* $RH, $RC, $RL, $RB ... */ })();</script><div hidden id="S:0"><!DOCTYPE html><html lang="en"><head><meta charset="utf-8"/><title>Hello</title></head><body><p>Body text</p></body></html></div><script>$RC(0)</script>

A related difference shows up even when nothing is pending at flush time: with the same outer <Suspense>, Redact writes <!--$0--> before <!DOCTYPE html> and <!--/$--> after </html>, so comments sit outside the document element. React writes nothing before the doctype.

Expected

Once allReady has resolved before the first read, every completed boundary is written inline in place, with no fallback, no boundary script and no hidden segment, as React does. This is the pattern static renderers rely on (react-email, and anything else that awaits allReady to get a complete document).

Environment

@tanstack/redact 0.3.1, React 19.3.1, react-email 6.11.16 (@react-email/render 2.3.1), Node 26.13.1.

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

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de TanStack/redact

Toutes les issues de TanStack/redact

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.