CodeSampleX

示例

react 19.2.8: StrictMode

已验证示例 — npm react 19.2.8: StrictMode. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: StrictMode is exported as a symbol from react matching…

sha256:bc7b608fee0220bc8876958bcc8c44ca64321465c792194df44cfcfbb22c03a2

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 linux 24 · ubuntu · glibc 2.39 x64 npm

验证运行环境

环境 契约 阶段 运行日期
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-27

案例

HOW
目标
verify react.StrictMode in pkg:npm/react@19.2.8
包
符号
  • react.StrictMode
创建时间
2026-08-27T15:04:42Z

契约

  1. StrictMode is exported as a symbol from react matching Symbol.for('react.strict_mode')
  2. StrictMode is distinct from other built-in React symbols including Fragment, Profiler, Suspense, and Activity
  3. React.createElement with StrictMode produces a valid React element with type StrictMode and $$typeof react.transitional.element
  4. StrictMode container element is counted as 1 element by React.Children.count and passes React.Children.only
  5. React.cloneElement preserves StrictMode element type while applying updated key, props, and children
  6. Helper utilities isStrictModeElement, wrapInStrictMode, and cloneStrictMode correctly inspect, wrap, and clone StrictMode elements

文件

  • NOTES.md
  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.mjs
  • test/contract.mjs

下载源代码构件 (tar.gz)

源代码

NOTES.md
# React 19 StrictMode Contract and Behavior

## Prior Search Results

A search for `pkg:npm/react@19.2.8` `react.StrictMode` returned `NO_SAFE_MATCH`.

## Key Behaviors Proven

1. **Symbol Export and Identity**: `React.StrictMode` and named export `StrictMode` are exported from `react` as a `symbol` matching the global `Symbol.for('react.strict_mode')`.
2. **Built-in Type Distinctness**: `StrictMode` is uniquely distinct from other built-in React symbols including `Fragment`, `Profiler`, `Suspense`, and `Activity`.
3. **Element Creation and React 19 Structure**: Calling `React.createElement(StrictMode, ...)` produces a valid React element with `$$typeof` equal to `Symbol.for('react.transitional.element')` and `type` equal to `StrictMode`.
4. **React.Children Utility Compatibility**: `React.Children.count` treats a `StrictMode` element as a single container, `React.Children.only` accepts it, and nested children are accurately accessible via `props.children`.
5. **Element Cloning**: `React.cloneElement` clones `StrictMode` elements preserving the component type while updating props, keys, and children.
6. **Helper Utilities**: `isStrictModeElement`, `wrapInStrictMode`, and `cloneStrictMode` provide safe inspection and transformation wrappers around `StrictMode`.
PROMPT.md
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.StrictMode in pkg:npm/react@19.2.8
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/react@19.2.8
Demonstrate these symbols/APIs:
  - react.StrictMode

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.
csx.json
{"case":{"caseId":"case:sha256:e08378861a4ed648aa6df052bd44a1cf777c3c773b8d111ed52547d2e6e415d6","contract":["StrictMode is exported as a symbol from react matching Symbol.for('react.strict_mode')","StrictMode is distinct from other built-in React symbols including Fragment, Profiler, Suspense, and Activity","React.createElement with StrictMode produces a valid React element with type StrictMode and $$typeof react.transitional.element","StrictMode container element is counted as 1 element by React.Children.count and passes React.Children.only","React.cloneElement preserves StrictMode element type while applying updated key, props, and children","Helper utilities isStrictModeElement, wrapInStrictMode, and cloneStrictMode correctly inspect, wrap, and clone StrictMode elements"],"goal":"verify react.StrictMode in pkg:npm/react@19.2.8","kind":"HOW","packages":["pkg:npm/react@19.2.8"],"schemaVersion":1,"symbols":["react.StrictMode"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/react@19.2.8"],"schemaVersion":1,"subject":"pkg:npm/react@19.2.8","symbols":["react.StrictMode"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "npm-react-strict-mode",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "npm-react-strict-mode",
      "version": "1.0.0",
      "dependencies": {
        "react": "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"
      }
    }
  }
}
package.json
{
  "name": "npm-react-strict-mode",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "dependencies": {
    "react": "19.2.8"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify react.StrictMode in pkg:npm/react@19.2.8",
  "kind": "HOW",
  "packages": [
    "pkg:npm/react@19.2.8"
  ],
  "symbols": [
    "react.StrictMode"
  ]
}
src/index.mjs
import React, { StrictMode } from 'react';

/**
 * Checks whether a given object is a valid React StrictMode element.
 * @param {any} node
 * @returns {boolean}
 */
export function isStrictModeElement(node) {
  return React.isValidElement(node) && node.type === StrictMode;
}

/**
 * Wraps children in a React StrictMode element.
 * @param {any} children
 * @param {object} [props={}]
 * @returns {import('react').ReactElement}
 */
export function wrapInStrictMode(children, props = {}) {
  return React.createElement(StrictMode, props, children);
}

/**
 * Clones a StrictMode element with additional props or new children.
 * @param {import('react').ReactElement} element
 * @param {object} [nextProps={}]
 * @param {any} [nextChildren]
 * @returns {import('react').ReactElement}
 */
export function cloneStrictMode(element, nextProps = {}, nextChildren) {
  if (!isStrictModeElement(element)) {
    throw new TypeError('Expected a React StrictMode element');
  }
  if (nextChildren !== undefined) {
    return React.cloneElement(element, nextProps, nextChildren);
  }
  return React.cloneElement(element, nextProps);
}

export { StrictMode };
export default StrictMode;
test/contract.mjs
import assert from 'node:assert/strict';
import React, { StrictMode } from 'react';
import {
  isStrictModeElement,
  wrapInStrictMode,
  cloneStrictMode
} from '../src/index.mjs';

// 1. Export identity & Symbol definition:
// StrictMode is exported as a symbol from 'react' matching Symbol.for('react.strict_mode')
assert.equal(typeof StrictMode, 'symbol', 'StrictMode should be of type symbol');
assert.equal(StrictMode, React.StrictMode, 'Named export StrictMode matches React.StrictMode');
assert.equal(StrictMode, Symbol.for('react.strict_mode'), 'StrictMode matches Symbol.for("react.strict_mode")');

// Distinct from other built-in React symbols
assert.notEqual(StrictMode, React.Fragment, 'StrictMode is distinct from Fragment');
assert.notEqual(StrictMode, React.Profiler, 'StrictMode is distinct from Profiler');
assert.notEqual(StrictMode, React.Suspense, 'StrictMode is distinct from Suspense');
assert.notEqual(StrictMode, React.Activity, 'StrictMode is distinct from Activity');

// 2. React Element Creation & React 19 Transitional Element structure:
const childText = 'Hello StrictMode';
const element = React.createElement(StrictMode, { key: 'strict-key' }, childText);

assert.ok(React.isValidElement(element), 'Element created with StrictMode is a valid React element');
assert.equal(element.type, StrictMode, 'Element type is StrictMode symbol');
assert.equal(element.key, 'strict-key', 'Element key is preserved');
assert.equal(element.props.children, childText, 'Element props.children contains the child content');
assert.equal(element.$$typeof, Symbol.for('react.transitional.element'), 'React 19 element $$typeof is react.transitional.element');

// 3. React.Children utility behavior:
const multiChildElement = React.createElement(
  StrictMode,
  null,
  React.createElement('span', { key: '1' }, 'Child 1'),
  React.createElement('span', { key: '2' }, 'Child 2')
);

assert.equal(React.Children.count(multiChildElement), 1, 'React.Children.count views StrictMode container as 1 element');
assert.equal(React.Children.only(multiChildElement), multiChildElement, 'React.Children.only succeeds for StrictMode element');

const extractedChildren = React.Children.toArray(multiChildElement.props.children);
assert.equal(extractedChildren.length, 2, 'React.Children.toArray extracts nested children correctly');
assert.equal(extractedChildren[0].props.children, 'Child 1');
assert.equal(extractedChildren[1].props.children, 'Child 2');

// 4. React.cloneElement support:
const clonedElement = React.cloneElement(element, { key: 'cloned-key', 'data-custom': 'strict-val' }, 'New Child');
assert.ok(React.isValidElement(clonedElement), 'Cloned element is valid');
assert.equal(clonedElement.type, StrictMode, 'Cloned element preserves StrictMode type');
assert.equal(clonedElement.key, 'cloned-key', 'Cloned element has updated key');
assert.equal(clonedElement.props['data-custom'], 'strict-val', 'Cloned element includes new custom prop');
assert.equal(clonedElement.props.children, 'New Child', 'Cloned element has updated children');

// 5. Helper module integration (isStrictModeElement, wrapInStrictMode, cloneStrictMode):
assert.equal(isStrictModeElement(element), true, 'isStrictModeElement returns true for StrictMode element');
assert.equal(isStrictModeElement(React.createElement('div', null)), false, 'isStrictModeElement returns false for div element');
assert.equal(isStrictModeElement(null), false, 'isStrictModeElement returns false for null');
assert.equal(isStrictModeElement({}), false, 'isStrictModeElement returns false for plain object');

const wrapped = wrapInStrictMode(React.createElement('p', null, 'Strict Paragraph'), { key: 'p-wrapper' });
assert.ok(isStrictModeElement(wrapped), 'wrapInStrictMode creates valid StrictMode element');
assert.equal(wrapped.key, 'p-wrapper');

const reCloned = cloneStrictMode(wrapped, { key: 'p-wrapper-updated' });
assert.equal(reCloned.key, 'p-wrapper-updated');
assert.ok(isStrictModeElement(reCloned));

assert.throws(
  () => cloneStrictMode(React.createElement('div', null)),
  /Expected a React StrictMode element/,
  'cloneStrictMode throws TypeError when given non-StrictMode element'
);

console.log('All react.StrictMode contract assertions passed successfully!');

原始种子者

匿名