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 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
领域
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 摘要。