renderToStream: rendered content with $`, $& or $' is corrupted when a root hole is filled (String.replace patterns)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 82/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript, typescript
调研方向
从 packages/web/src/server.ts 中的 resolveRootHoles() 开始,issue 在这里指出了两个用于插入渲染内容的 String.replace 调用。检查 renderToStream root holes 的现有测试,并补充对包含 $`、$\u0026、$' 和 $$ 的内容的覆盖。issue 报告称替换回调会按原样插入内容;完成标准是流式传输的 HTML 保留这些字符,并与预期输出一致。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
renderToStream fills its root holes with String.prototype.replace and passes the rendered HTML as the replacement string:
// packages/web/src/server.ts, resolveRootHoles()
html = html.replace(marker, res.t[0]);
// …
html = html.replace(marker, out);
A replacement string is parsed for special patterns, so any $`, $&, $' or $$ in the rendered content is substituted instead of written. In the shipped 2.0.4 build that's dist/server.js, server.dev.js and server.observe.js. Each has two calls, in renderToStream → resolveRootHoles. Upstream's next branch has the same code.
The output is wrong whenever text in a root hole contains those characters. For example: docs or code samples that show `$`, prices, regexes, or a $' in user content.
$`inserts the HTML before the marker (here, the opening<p>).$&inserts the marker itself (<!--rh0-->).$'inserts everything after the marker, and with more content after it, that can duplicate a large part of the document.
The same applies to serialized data in a hole: in our case the hydration payload for a route loader carried a Markdown string with `$`. That payload reached the browser changed, so the client rendered different text from the server and hydration missed keys.
Your Example Website or App
Inline below (no deployed app needed).
Steps to Reproduce the Bug or Issue
App.jsx:
import { createMemo } from "solid-js";
// Text from an async source, so the root render leaves a hole that renderToStream fills later.
export function App() {
const price = createMemo(async () => "Total: `$` 5 (`$&` and `$'` too)");
return <p>{price()}</p>;
}
Compiled for the server with @solidjs/compiler (generate: "ssr", hydratable: false), then:
import { renderToStream } from "@solidjs/web";
import { App } from "./App.mjs";
// The text as HTML: escape() turns & into &.
const expected = "Total: `$` 5 (`$&` and `$'` too)";
let html = "";
await new Promise((resolve) =>
renderToStream(() => App()).pipe({ write: (chunk) => (html += chunk), end: resolve }),
);
const p = /<p>([\s\S]*?)<\/p>/.exec(html)?.[1];
console.log("expected:", JSON.stringify(expected));
console.log("received:", JSON.stringify(p));
Output with solid-js 2.0.4, @solidjs/web 2.0.4 (Node 26):
expected: "Total: `$` 5 (`$&` and `$'` too)"
received: "Total: `<p> 5 (`<!--rh0-->amp;` and `"
Expected behavior
The hole is filled with the rendered HTML as written:
received: "Total: `$` 5 (`$&` and `$'` too)"
Passing a function as the replacement does that, because a function's return value is inserted literally:
- html = html.replace(marker, res.t[0]);
+ html = html.replace(marker, () => res.t[0]);
…
- html = html.replace(marker, out);
+ html = html.replace(marker, () => out);
We've run with that change patched in (bun patch) and the repro above prints the expected text. replacePlaceholder already splices with slice and isn't affected.
Screenshots or Videos
No response
Platform
- OS: macOS
- Runtime: Node 26.13 (also seen in workerd through Vite's dev server)
- Version:
solid-js2.0.4,@solidjs/web2.0.4
Additional context
Found while clearing hydration diagnostics on an SSR docs site: the page with the `$` text was the only one whose loader payload differed between server and client.
- 主要语言
- TypeScript
- 星标
- 37k
- 派生
- 1.2k
- 平均合并
- 8 小时 43 分钟
- 30 天内合并 PR
- 365
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
solidjs/solid 的其他 Issue
-
难度 1/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 38/100
维护者通常 1 天内回复
-
[2.0.4] Nested `<Errored>`: the outer boundary stays on an error the inner one rethrew, after the next error is one the inner one handles可能已有人在做 @MilindChatrabhuji 于 2 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 25/100
维护者通常 1 天内回复
-
[2.0.4] A waiting action started from a cleanup holds back an effect's write that reacts to the same landing (follow-up to #5251)可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 4/5 3-5 天 新手友好度 38/100
维护者通常 1 天内回复
相似的 Issue
-
agents-window vscode api adoption
难度 2/5 1-3 小时 新手友好度 77/100
alefragnani/vscode-copy-word#126 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
opensro-dev/opensro#4949 ·
维护者通常 1 天内回复
-
agent:linux priority:high
难度 2/5 1-3 小时 新手友好度 76/100
fa0311/better-tokuly#1204 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 73/100
维护者通常 1 天内回复
-
enhancement impeccable priority: low
难度 2/5 1-3 小时 新手友好度 78/100
nledford/Ladderback#1891 ·
维护者通常 1 天内回复