샘플
react 19.2.8: Choose between renderToString and renderToStaticMarkup without breaking hydration
검증된 샘플 — npm react 19.2.8: Choose between renderToString and renderToStaticMarkup without breaking hydration. node 22 · linux alpine/x64 · docker에서 contract를…
sha256:d2d2a344c3d423d5725df086dd3263d1813bf6519cd592f5302c538364efc8b2
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 2
- 빌드한 서명 키
- 2
선언된 환경
node 22 linux x64 node 22 javascript npm
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-13 |
| node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-17 |
케이스
FIX- 목표
- Choose between renderToString and renderToStaticMarkup without breaking hydration
- 심벌
-
- renderToString
- renderToStaticMarkup
- createElement
- 환경
- node 22
- 생성일
- 2026-08-13T18:13:46Z
컨트랙트
- render a component whose children include adjacent text nodes
- assert renderToString emits a comment separator at the text boundary
- assert renderToStaticMarkup omits it and is otherwise identical
- assert interpolated text is HTML-escaped
파일
- csx.json
- package-lock.json
- package.json
- src/index.mjs
- test/contract.mjs
소스
{"case":{"caseId":"case:sha256:0ee6f5151b89d55d7a880db5e223ba807e6c2f55fab2db04e2eff26258962532","constraints":{"moduleSystem":"esm","runtime":"node"},"contract":["render a component whose children include adjacent text nodes","assert renderToString emits a comment separator at the text boundary","assert renderToStaticMarkup omits it and is otherwise identical","assert interpolated text is HTML-escaped"],"goal":"Choose between renderToString and renderToStaticMarkup without breaking hydration","kind":"FIX","packages":["pkg:npm/react@19.2.8","pkg:npm/react-dom@19.2.8"],"schemaVersion":1,"symbols":["renderToString","renderToStaticMarkup","createElement"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"javascript","moduleSystem":"esm","os":"linux","packageManager":"npm","runtime":"node","runtimeVersion":"22","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/react@19.2.8","pkg:npm/react-dom@19.2.8"],"schemaVersion":1,"symbols":["renderToString","renderToStaticMarkup","createElement"],"verifierAdapter":"node-typescript@1"}
{
"name": "csx-sample-react-render-to-string",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "csx-sample-react-render-to-string",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"react": "19.2.8",
"react-dom": "19.2.8"
}
},
"node_modules/react": {
"version": "19.2.8",
"resolved": "https://registry.npmjs.org/react/-/react-19.2.8.tgz",
"integrity": "sha512-PWaYA1L/q9u2u7xYQi+Y3L3Yfnie7XyLeaJICV1MGD6LprsBxcAqGjYyr0eY3p+QdsA+x/Irkt4Qif8D63+Sbw==",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/react-dom": {
"version": "19.2.8",
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.2.8.tgz",
"integrity": "sha512-rVprimfGBG3DR+Tq0IQG2DT5PxKth1WIGDmj5yPmlzr4YBe7uyE+Du4oVqTDXZSHGGGXRtTJEGSSePyQCMBglQ==",
"license": "MIT",
"dependencies": {
"scheduler": "^0.27.0"
},
"peerDependencies": {
"react": "^19.2.8"
}
},
"node_modules/scheduler": {
"version": "0.27.0",
"resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.27.0.tgz",
"integrity": "sha512-eNv+WrVbKu1f3vbYJT/xtiF5syA5HPIMtf9IgY/nKg0sWqzAUEvqY/xm7OcZc/qafLx/iO9FgOmeSAp4v5ti/Q==",
"license": "MIT"
}
}
}
{
"name": "csx-sample-react-render-to-string",
"version": "1.0.0",
"private": true,
"type": "module",
"license": "MIT-0",
"dependencies": {
"react": "19.2.8",
"react-dom": "19.2.8"
}
}
import { createElement as h } from 'react';
import { renderToStaticMarkup, renderToString } from 'react-dom/server';
// react-dom/server is a SEPARATE entry point; importing renderToString
// from 'react-dom' fails.
//
// The two renderers differ in one specific place: where a text node sits
// next to another text node, renderToString emits a `<!-- -->` separator
// so hydration can find the boundary between them. renderToStaticMarkup
// omits it. Markup that will be hydrated must come from renderToString —
// using static markup saves a few bytes and then fails hydration on
// exactly those boundaries. A tree with no adjacent text nodes produces
// identical output from both, which is why the difference is easy to miss
// in a small test and only shows up in real content.
function Line({ user, count }) {
// "signed in as " and {user} are adjacent text nodes: the boundary case.
return h('p', null, 'signed in as ', user, ' (', count, ' items)');
}
export function hydratableHTML(props) {
return renderToString(h(Line, props));
}
export function staticHTML(props) {
return renderToStaticMarkup(h(Line, props));
}
export function escaped(text) {
return renderToStaticMarkup(h('div', null, text));
}
import { strict as assert } from 'node:assert';
import { hydratableHTML, staticHTML, escaped } from '../src/index.mjs';
const props = { user: 'codesamplex', count: 3 };
const hydratable = hydratableHTML(props);
const staticOnly = staticHTML(props);
// Both carry the same visible text.
for (const html of [hydratable, staticOnly]) {
assert.match(html, /<p>/);
assert.match(html, /signed in as/);
assert.match(html, /codesamplex/);
}
// The difference: separators between adjacent text nodes.
assert.ok(hydratable.includes('<!-- -->'),
`renderToString should separate adjacent text nodes: ${hydratable}`);
assert.ok(!staticOnly.includes('<!-- -->'),
`renderToStaticMarkup should omit them: ${staticOnly}`);
assert.notEqual(hydratable, staticOnly);
// Strip the separators and the two agree exactly — the markup is the same
// document, only the hydration boundaries differ.
assert.equal(hydratable.split('<!-- -->').join(''), staticOnly);
// React escapes interpolated text; it is not a raw template engine.
const xss = escaped('<script>alert(1)</script>');
assert.ok(!xss.includes('<script>'), xss);
assert.match(xss, /<script>/);
console.log('CONTRACT PASS: renderToString kept text boundaries that renderToStaticMarkup drops');