サンプル
react-dom 19.0.0: createRoot
検証済みサンプル — npm react-dom 19.0.0: createRoot. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: createRoot is exported as a function from…
sha256:ff9a79a4b52513040c2cde5860e1b49d7a36b9ddbe5ef9ec72ba5256ea5fb8b8
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 1
- ビルドした署名鍵
- 1
宣言された環境
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-09-06 |
ケース
HOW- ゴール
- verify react-dom.createRoot in pkg:npm/react-dom@19.0.0
- パッケージ
- シンボル
-
- react-dom.createRoot
- 環境
- node 22.23.2
- 作成日
- 2026-09-06T20:59:50Z
コントラクト
- createRoot is exported as a function from react-dom/client
- createRoot(null) and createRoot({}) throw Error 'Target container is not a DOM element.'
- createRoot(container) returns a root object with render and unmount methods
- root.render(element) renders React elements into the target DOM container
- root.unmount() unmounts the rendered tree and clears the container contents
- createRoot accepts optional configuration including identifierPrefix for React useId hooks
ファイル
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
ソース
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify react-dom.createRoot in pkg:npm/react-dom@19.0.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/react-dom@19.0.0
Demonstrate these symbols/APIs:
- react-dom.createRoot
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:144ef3bfe09de50745bea4980613d4261bd387e99491bdf6858a8b3f7d0a6bc8","contract":["createRoot is exported as a function from react-dom/client","createRoot(null) and createRoot({}) throw Error 'Target container is not a DOM element.'","createRoot(container) returns a root object with render and unmount methods","root.render(element) renders React elements into the target DOM container","root.unmount() unmounts the rendered tree and clears the container contents","createRoot accepts optional configuration including identifierPrefix for React useId hooks"],"goal":"verify react-dom.createRoot in pkg:npm/react-dom@19.0.0","kind":"HOW","packages":["pkg:npm/react-dom@19.0.0"],"schemaVersion":1,"symbols":["react-dom.createRoot"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/react-dom@19.0.0"],"schemaVersion":1,"subject":"pkg:npm/react-dom@19.0.0","symbols":["react-dom.createRoot"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-react-dom-createroot",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-react-dom-createroot",
"version": "1.0.0",
"dependencies": {
"react": "19.0.0",
"react-dom": "19.0.0"
}
},
"node_modules/react": {
"version": "19.0.0",
"resolved": "https://registry.npmjs.org/react/-/react-19.0.0.tgz",
"integrity": "sha512-V8AVnmPIICiWpGfm6GLzCR/W5FXLchHop40W4nXBmdlEceh16rCN8O8LNWm5bh5XUX91fh7KpA+W0TgMKmgTpQ==",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/react-dom": {
"version": "19.0.0",
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.0.0.tgz",
"integrity": "sha512-4GV5sHFG0e/0AD4X+ySy6UJd3jVl1iNsNHdpad0qhABJ11twS3TTBnseqsKurKcsNqCEFeGL3uLpVChpIO3QfQ==",
"license": "MIT",
"dependencies": {
"scheduler": "^0.25.0"
},
"peerDependencies": {
"react": "^19.0.0"
}
},
"node_modules/scheduler": {
"version": "0.25.0",
"resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.25.0.tgz",
"integrity": "sha512-xFVuu11jh+xcO7JOAGJNOXld8/TcEHK/4CituBUeUb5hqxJLj9YuemAEuvm9gQ/+pgXYfbQuqAkiYu+u7YEsNA==",
"license": "MIT"
}
}
}
{
"name": "sample-react-dom-createroot",
"version": "1.0.0",
"private": true,
"dependencies": {
"react": "19.0.0",
"react-dom": "19.0.0"
}
}
{
"schemaVersion": 1,
"goal": "verify react-dom.createRoot in pkg:npm/react-dom@19.0.0",
"kind": "HOW",
"packages": [
"pkg:npm/react-dom@19.0.0"
],
"symbols": [
"react-dom.createRoot"
]
}
import { createRoot } from "react-dom/client";
/**
* Creates and mounts a React root into a DOM container element.
*
* @param {Element|Document|DocumentFragment} container
* @param {import("react").ReactNode} element
* @param {object} [options]
* @returns {{ root: object, unmount: () => void }}
*/
export function createAndMountRoot(container, element, options = {}) {
const root = createRoot(container, options);
root.render(element);
return {
root,
unmount: () => root.unmount()
};
}
export { createRoot };
import assert from "node:assert/strict";
import React from "react";
import { createRoot } from "react-dom/client";
import { flushSync } from "react-dom";
import { createAndMountRoot } from "../src/index.mjs";
// Setup minimal offline DOM environment for Node.js
class Node {}
class Element extends Node {}
class HTMLElement extends Element {}
class HTMLIFrameElement extends HTMLElement {}
class Document extends Node {}
class DocumentFragment extends Node {}
const window = {
event: undefined,
Node,
Element,
HTMLElement,
HTMLIFrameElement,
Document,
DocumentFragment
};
globalThis.window = window;
globalThis.Node = Node;
globalThis.Element = Element;
globalThis.HTMLElement = HTMLElement;
globalThis.HTMLIFrameElement = HTMLIFrameElement;
globalThis.Document = Document;
globalThis.DocumentFragment = DocumentFragment;
function createMockDocument() {
const docListeners = new Map();
const doc = {
nodeType: 9,
nodeName: "#document",
activeElement: null,
defaultView: window,
createElement(tag) {
const elListeners = new Map();
const elChildren = [];
const el = {
nodeType: 1,
nodeName: tag.toUpperCase(),
tagName: tag.toUpperCase(),
childNodes: elChildren,
children: elChildren,
style: {},
ownerDocument: doc,
setAttribute(k, v) { this[k] = v; },
getAttribute(k) { return this[k] || null; },
appendChild(child) { elChildren.push(child); return child; },
removeChild(child) {
const idx = elChildren.indexOf(child);
if (idx >= 0) elChildren.splice(idx, 1);
return child;
},
insertBefore(newChild, refChild) {
const idx = elChildren.indexOf(refChild);
if (idx >= 0) elChildren.splice(idx, 0, newChild);
else elChildren.push(newChild);
return newChild;
},
addEventListener(event, handler) {
if (!elListeners.has(event)) elListeners.set(event, []);
elListeners.get(event).push(handler);
},
removeEventListener(event, handler) {
if (elListeners.has(event)) {
const arr = elListeners.get(event);
const idx = arr.indexOf(handler);
if (idx >= 0) arr.splice(idx, 1);
}
}
};
return el;
},
createTextNode(text) {
return {
nodeType: 3,
nodeName: "#text",
nodeValue: String(text),
textContent: String(text),
ownerDocument: doc
};
},
createComment(data) {
return {
nodeType: 8,
nodeName: "#comment",
nodeValue: String(data),
ownerDocument: doc
};
},
addEventListener(event, handler) {
if (!docListeners.has(event)) docListeners.set(event, []);
docListeners.get(event).push(handler);
},
removeEventListener(event, handler) {
if (docListeners.has(event)) {
const arr = docListeners.get(event);
const idx = arr.indexOf(handler);
if (idx >= 0) arr.splice(idx, 1);
}
}
};
window.document = doc;
return doc;
}
const doc = createMockDocument();
globalThis.document = doc;
// 1. Symbol availability: createRoot is exported as a function from react-dom/client
assert.strictEqual(typeof createRoot, "function", "createRoot must be exported as a function");
// 2. Error handling: createRoot(null) and createRoot({}) throw Error 'Target container is not a DOM element.'
assert.throws(
() => createRoot(null),
/Target container is not a DOM element/,
"createRoot(null) must throw Target container is not a DOM element"
);
assert.throws(
() => createRoot({}),
/Target container is not a DOM element/,
"createRoot({}) must throw Target container is not a DOM element"
);
// 3. Create root on valid DOM element: createRoot(container) returns a root object with render and unmount methods
const container = doc.createElement("div");
const root = createRoot(container);
assert.strictEqual(typeof root.render, "function", "root must have a render method");
assert.strictEqual(typeof root.unmount, "function", "root must have an unmount method");
// 4. Render element: root.render(element) renders React elements into the target DOM container
flushSync(() => {
root.render(React.createElement("span", { id: "test-node" }, "React 19.0.0 createRoot verified"));
});
assert.strictEqual(container.childNodes.length, 1, "Container should have 1 child node after render");
assert.strictEqual(container.childNodes[0].tagName, "SPAN", "Rendered child tag should be SPAN");
// 5. Unmount root: root.unmount() unmounts the rendered tree and clears the container contents
flushSync(() => {
root.unmount();
});
assert.strictEqual(container.childNodes.length, 0, "Container should have 0 children after unmount");
// 6. Options support: createRoot accepts optional configuration including identifierPrefix for React useId hooks
const optContainer = doc.createElement("div");
const optRoot = createRoot(optContainer, {
identifierPrefix: "custom-prefix-"
});
function AppWithId() {
const generatedId = React.useId();
return React.createElement("div", { id: generatedId }, "Component with ID");
}
flushSync(() => {
optRoot.render(React.createElement(AppWithId));
});
assert.strictEqual(optContainer.childNodes.length, 1, "Option container should have 1 child");
assert.ok(
optContainer.childNodes[0].id && optContainer.childNodes[0].id.includes("custom-prefix-"),
"Generated ID should contain identifierPrefix"
);
flushSync(() => {
optRoot.unmount();
});
assert.strictEqual(optContainer.childNodes.length, 0, "Option container should be empty after unmount");
// 7. Helper verification
const helperContainer = doc.createElement("div");
let helperHandle;
flushSync(() => {
helperHandle = createAndMountRoot(
helperContainer,
React.createElement("p", null, "Mounted via helper")
);
});
assert.strictEqual(helperContainer.childNodes.length, 1, "Helper container should have 1 child");
flushSync(() => {
helperHandle.unmount();
});
assert.strictEqual(helperContainer.childNodes.length, 0, "Helper container should be empty after unmount");
console.log("All contract assertions passed successfully.");
オリジンシーダー
匿名