CodeSampleX

Пример

react-is 17.0.2: Suspense

Проверенный пример — npm react-is 17.0.2: Suspense. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден: react-is exports Suspense matching…

sha256:ab354c9d550fe4379975bcb74d72c0f3c2aced63bc163ff19b445607f3a87f3f

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда linux 24 · ubuntu · glibc 2.39 x64 npm

Среды запусков проверки

Окружение Контракт Этапы Запуск
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-is.Suspense in pkg:npm/react-is@17.0.2
Пакеты
Символы
  • react-is.Suspense
Создан
2026-09-06T11:14:11Z

Контракт

  1. react-is exports Suspense matching Symbol.for('react.suspense')
  2. isValidElementType identifies Suspense as a valid React element type
  3. isSuspense detects valid React 17 Suspense elements
  4. isSuspense returns false for Suspense symbol itself, non-suspense elements, and primitives
  5. typeOf returns Suspense symbol for valid suspense elements and undefined for non-elements

Файлы

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

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

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-is.Suspense in pkg:npm/react-is@17.0.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/react-is@17.0.2
Demonstrate these symbols/APIs:
  - react-is.Suspense

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:2684a406ecaf61f361c5277d5a2c4682f6edf98e2ca14b85e714b5b11d6bcf91","contract":["react-is exports Suspense matching Symbol.for('react.suspense')","isValidElementType identifies Suspense as a valid React element type","isSuspense detects valid React 17 Suspense elements","isSuspense returns false for Suspense symbol itself, non-suspense elements, and primitives","typeOf returns Suspense symbol for valid suspense elements and undefined for non-elements"],"goal":"verify react-is.Suspense in pkg:npm/react-is@17.0.2","kind":"HOW","packages":["pkg:npm/react-is@17.0.2"],"schemaVersion":1,"symbols":["react-is.Suspense"]},"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-is@17.0.2"],"schemaVersion":1,"subject":"pkg:npm/react-is@17.0.2","symbols":["react-is.Suspense"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-react-is-suspense",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-react-is-suspense",
      "version": "1.0.0",
      "dependencies": {
        "react-is": "17.0.2"
      }
    },
    "node_modules/react-is": {
      "version": "17.0.2",
      "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
      "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-react-is-suspense",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of react-is.Suspense in React 17",
  "type": "module",
  "main": "src/index.js",
  "dependencies": {
    "react-is": "17.0.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify react-is.Suspense in pkg:npm/react-is@17.0.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/react-is@17.0.2"
  ],
  "symbols": [
    "react-is.Suspense"
  ]
}
src/index.js
import {
  Suspense,
  isSuspense,
  typeOf,
  isValidElementType,
  Element,
} from 'react-is';

export { Suspense, Element };

/**
 * Creates a React 17 element representation.
 *
 * @param {*} type - The element type.
 * @param {Object} [props={}] - Element properties.
 * @returns {Object} React element object.
 */
export function createElement(type, props = {}) {
  return {
    $$typeof: Element || Symbol.for('react.element'),
    type,
    props,
    key: null,
    ref: null,
  };
}

/**
 * Creates a React 17 Suspense element representation.
 *
 * @param {*} [fallback=null] - Fallback prop for Suspense.
 * @param {*} [children] - Children to include in props.
 * @returns {Object} React Suspense element object.
 */
export function createSuspenseElement(fallback = null, children) {
  const props = { fallback };
  if (children !== undefined) {
    props.children = children;
  }
  return createElement(Suspense, props);
}

/**
 * Checks whether a given object is a React Suspense element.
 *
 * @param {*} value - The value to test.
 * @returns {boolean} True if the value is a Suspense element.
 */
export function checkIsSuspense(value) {
  return isSuspense(value);
}

/**
 * Checks whether a given type is a valid React element type.
 *
 * @param {*} type - The type to test.
 * @returns {boolean} True if the type is valid.
 */
export function checkIsValidElementType(type) {
  return isValidElementType(type);
}

/**
 * Inspects the React type of a given value.
 *
 * @param {*} value - The value to inspect.
 * @returns {*|undefined} Type symbol or undefined.
 */
export function inspectTypeOf(value) {
  return typeOf(value);
}
test/contract.mjs
import assert from 'node:assert/strict';
import {
  Suspense,
  Element,
  createElement,
  createSuspenseElement,
  checkIsSuspense,
  checkIsValidElementType,
  inspectTypeOf,
} from '../src/index.js';
import reactIs from 'react-is';

// Contract 1: react-is exports Suspense matching Symbol.for('react.suspense')
assert.equal(typeof Suspense, 'symbol', 'Suspense must be a symbol');
assert.equal(Suspense, Symbol.for('react.suspense'), 'Suspense must match Symbol.for("react.suspense")');
assert.equal(reactIs.Suspense, Suspense, 'Default import Suspense must match named import Suspense');

// Contract 2: isValidElementType identifies Suspense as a valid React element type
assert.equal(checkIsValidElementType(Suspense), true, 'Suspense must be recognized as a valid element type');
assert.equal(reactIs.isValidElementType(Suspense), true, 'react-is.isValidElementType must return true for Suspense');
assert.equal(checkIsValidElementType('div'), true, 'String tag must be a valid element type');
assert.equal(checkIsValidElementType(() => null), true, 'Function component must be a valid element type');
assert.equal(checkIsValidElementType(123), false, 'Number must not be a valid element type');
assert.equal(checkIsValidElementType(null), false, 'null must not be a valid element type');
assert.equal(checkIsValidElementType(undefined), false, 'undefined must not be a valid element type');

// Contract 3: isSuspense detects valid React 17 Suspense elements
const suspenseWithChildren = createSuspenseElement('Loading...', ['child1', 'child2']);
assert.equal(checkIsSuspense(suspenseWithChildren), true, 'Suspense element with children must be detected by checkIsSuspense');
assert.equal(reactIs.isSuspense(suspenseWithChildren), true, 'Suspense element with children must be detected by reactIs.isSuspense');

const emptySuspense = createSuspenseElement();
assert.equal(checkIsSuspense(emptySuspense), true, 'Empty Suspense element must be detected by checkIsSuspense');
assert.equal(reactIs.isSuspense(emptySuspense), true, 'Empty Suspense element must be detected by reactIs.isSuspense');

// Contract 4: isSuspense returns false for Suspense symbol itself, non-suspense elements, and primitives
assert.equal(checkIsSuspense(Suspense), false, 'Suspense symbol itself is not an element instance');
assert.equal(reactIs.isSuspense(Suspense), false, 'Suspense symbol itself must return false from isSuspense');

const divElement = createElement('div', { id: 'root' });
assert.equal(checkIsSuspense(divElement), false, 'Plain div element must not be identified as a Suspense element');
assert.equal(reactIs.isSuspense(divElement), false, 'Plain div element must return false from isSuspense');

const fragmentElement = createElement(Symbol.for('react.fragment'));
assert.equal(checkIsSuspense(fragmentElement), false, 'Fragment element must not be identified as a Suspense element');

const transitionalSuspense = {
  $$typeof: Symbol.for('react.transitional.element'),
  type: Suspense,
  props: {},
  key: null,
  ref: null,
};
assert.equal(checkIsSuspense(transitionalSuspense), false, 'Transitional element $$typeof is not recognized by React 17 react-is');

assert.equal(checkIsSuspense(null), false, 'null must return false');
assert.equal(checkIsSuspense(undefined), false, 'undefined must return false');
assert.equal(checkIsSuspense({}), false, 'Plain object must return false');
assert.equal(checkIsSuspense('react.suspense'), false, 'String must return false');
assert.equal(checkIsSuspense(42), false, 'Number must return false');

// Contract 5: typeOf returns Suspense symbol for valid suspense elements and undefined for non-elements
assert.equal(inspectTypeOf(suspenseWithChildren), Suspense, 'inspectTypeOf must return Suspense symbol for suspense element');
assert.equal(reactIs.typeOf(suspenseWithChildren), Suspense, 'reactIs.typeOf must return Suspense symbol for suspense element');
assert.equal(inspectTypeOf(emptySuspense), Suspense, 'inspectTypeOf must return Suspense symbol for empty suspense element');

assert.equal(inspectTypeOf(divElement), Element, 'inspectTypeOf returns Element symbol for plain element');
assert.equal(inspectTypeOf(fragmentElement), Symbol.for('react.fragment'), 'inspectTypeOf returns Fragment symbol');
assert.equal(inspectTypeOf(Suspense), undefined, 'inspectTypeOf returns undefined for Suspense symbol');
assert.equal(inspectTypeOf(null), undefined, 'inspectTypeOf returns undefined for null');
assert.equal(inspectTypeOf(undefined), undefined, 'inspectTypeOf returns undefined for undefined');
assert.equal(inspectTypeOf({}), undefined, 'inspectTypeOf returns undefined for plain object');
assert.equal(inspectTypeOf(transitionalSuspense), undefined, 'inspectTypeOf returns undefined for transitional element');

console.log('All react-is.Suspense contract assertions passed.');

Исходный сидер

аноним