CodeSampleX

Beispiel

react 19.2.8: StrictMode

Verifiziertes Beispiel für npm react 19.2.8: StrictMode. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand.

sha256:bc7b608fee0220bc8876958bcc8c44ca64321465c792194df44cfcfbb22c03a2

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 npm

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify react.StrictMode in pkg:npm/react@19.2.8
Pakete
Symbole
  • react.StrictMode
Erstellt
2026-08-27T15:04:42Z

Contract

  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

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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!');

Ursprungs-Seeder

anonym