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

未關閉
#182 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
42/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
nodejs, react, typescript
領域
backend, web-dev

研究方向

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.

由索引模型根據 Issue 內容生成。

描述

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.

主要語言
TypeScript
星號
640
分支
32
平均合併
1 小時 15 分鐘
30 天內合併 PR
7

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

TanStack/redact 的其他 Issue

查看 TanStack/redact 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。