renderToStream: rendered content with $`, $& or $' is corrupted when a root hole is filled (String.replace patterns)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 82/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- javascript, typescript
Línea de trabajo
Empieza en packages/web/src/server.ts, en resolveRootHoles(), donde el issue identifica dos llamadas a String.replace que insertan contenido renderizado. Revisa las pruebas existentes para renderToStream root holes y añade cobertura para contenido que incluya $`, $\u0026, $' y $$. El issue indica que los callbacks de reemplazo insertan el contenido literalmente; la tarea estará completa cuando el HTML transmitido conserve esos caracteres y coincida con la salida esperada.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 37k
- Forks
- 1.2k
- Merge medio
- 8 h 43 min
- PR fusionados (30 d)
- 365
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de solidjs/solid
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 38/100
Los mantenedores suelen responder en 1 día
-
[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 handlesPosiblemente ocupada @MilindChatrabhuji la tomó hace 2 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
Los mantenedores suelen responder en 1 día
-
[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)Quizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 38/100
Los mantenedores suelen responder en 1 día
Todos los issues de solidjs/solid
Issues similares
-
agents-window vscode api adoption
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
alefragnani/vscode-copy-word#126 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
opensro-dev/opensro#4949 ·
Los mantenedores suelen responder en 1 día
-
agent:linux priority:high
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
fa0311/better-tokuly#1204 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
saltbo/zpan#883 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
enhancement impeccable priority: low
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
nledford/Ladderback#1891 ·
Los mantenedores suelen responder en 1 día