CodeSampleX

샘플

react-is 17.0.2: ForwardRef

검증된 샘플 — npm react-is 17.0.2: ForwardRef. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: ForwardRef is exported as a symbol equal to…

sha256:ab06597cfe05f90b0dba080423da43c5b7546de20b9d7c4a99ff68f5eebf9386

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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-is.ForwardRef in pkg:npm/react-is@17.0.2
패키지
심벌
  • react-is.ForwardRef
환경
node 22.23.2
생성일
2026-09-06T03:08:22Z

컨트랙트

  1. ForwardRef is exported as a symbol equal to Symbol.for('react.forward_ref')
  2. isForwardRef correctly identifies React 17 forwardRef elements
  3. typeOf returns ForwardRef symbol for forwardRef elements
  4. isValidElementType returns true for forwardRef component
  5. isForwardRef rejects standard HTML elements, fragment elements, and context elements
  6. isForwardRef rejects non-element values, plain objects, raw forwardRef components, and primitives

파일

  • 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.ForwardRef 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.ForwardRef
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:69367b5549dcf1f40e4389453f9008af2391dbcbfce091c3338f957c32c0a331","constraints":{"executionContext":"node"},"contract":["ForwardRef is exported as a symbol equal to Symbol.for('react.forward_ref')","isForwardRef correctly identifies React 17 forwardRef elements","typeOf returns ForwardRef symbol for forwardRef elements","isValidElementType returns true for forwardRef component","isForwardRef rejects standard HTML elements, fragment elements, and context elements","isForwardRef rejects non-element values, plain objects, raw forwardRef components, and primitives"],"goal":"verify react-is.ForwardRef in pkg:npm/react-is@17.0.2","kind":"HOW","packages":["pkg:npm/react-is@17.0.2"],"schemaVersion":1,"symbols":["react-is.ForwardRef"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","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-is@17.0.2"],"schemaVersion":1,"subject":"pkg:npm/react-is@17.0.2","symbols":["react-is.ForwardRef"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-react-is-forward-ref",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-react-is-forward-ref",
      "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-forward-ref",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of react-is ForwardRef in React 17",
  "type": "module",
  "main": "src/index.js",
  "dependencies": {
    "react-is": "17.0.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify react-is.ForwardRef in pkg:npm/react-is@17.0.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/react-is@17.0.2"
  ],
  "symbols": [
    "react-is.ForwardRef"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
import {
  ForwardRef,
  isForwardRef,
  isValidElementType,
  typeOf,
} from 'react-is';

/**
 * Return the ForwardRef symbol from react-is.
 * In React 17, this corresponds to Symbol.for('react.forward_ref').
 *
 * @returns {symbol} The ForwardRef symbol.
 */
export function getForwardRefSymbol() {
  return ForwardRef;
}

/**
 * Check if the given element is a React ForwardRef element.
 *
 * @param {*} value - The value to inspect.
 * @returns {boolean} True if the value is a ForwardRef element.
 */
export function checkIsForwardRef(value) {
  return isForwardRef(value);
}

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

/**
 * Determine the element type symbol of a given React element using typeOf.
 *
 * @param {*} value - The React element to inspect.
 * @returns {symbol|undefined} The matched React symbol or undefined for non-elements.
 */
export function identifyElementType(value) {
  return typeOf(value);
}

/**
 * Helper to construct a synthetic React 17 ForwardRef component.
 *
 * @param {Function} [renderFn] - Render function for forwardRef component.
 * @returns {object} Synthetic forwardRef component.
 */
export function createSyntheticForwardRefComponent(renderFn = (props, ref) => null) {
  return {
    $$typeof: ForwardRef,
    render: renderFn,
  };
}

/**
 * Helper to construct a synthetic React 17 ForwardRef element.
 *
 * @param {object} forwardRefType - Component with $$typeof matching ForwardRef.
 * @param {object} [props={}] - Element props.
 * @returns {object} Synthetic React 17 element.
 */
export function createSyntheticForwardRefElement(forwardRefType, props = {}) {
  return {
    $$typeof: Symbol.for('react.element'),
    type: forwardRefType,
    props,
    key: null,
    ref: null,
  };
}

export {
  ForwardRef,
  isForwardRef,
  isValidElementType,
  typeOf,
};
test/contract.mjs
import assert from 'node:assert/strict';
import {
  ForwardRef,
  isForwardRef,
  isValidElementType,
  typeOf,
  getForwardRefSymbol,
  checkIsForwardRef,
  checkIsValidElementType,
  identifyElementType,
  createSyntheticForwardRefComponent,
  createSyntheticForwardRefElement,
} from '../src/index.js';

// 1. ForwardRef symbol export verification
assert.equal(typeof ForwardRef, 'symbol', 'ForwardRef must be exported as a symbol');
assert.equal(
  ForwardRef,
  Symbol.for('react.forward_ref'),
  'ForwardRef in React 17 must match Symbol.for("react.forward_ref")'
);
assert.equal(
  getForwardRefSymbol(),
  ForwardRef,
  'getForwardRefSymbol helper must return ForwardRef symbol'
);

// 2. isForwardRef function export verification
assert.equal(typeof isForwardRef, 'function', 'isForwardRef must be exported as a function');
assert.equal(typeof checkIsForwardRef, 'function', 'checkIsForwardRef helper must be a function');

// 3. isValidElementType verification for forwardRef component
const forwardRefComponent = createSyntheticForwardRefComponent();
assert.equal(
  isValidElementType(forwardRefComponent),
  true,
  'isValidElementType must return true for forwardRef component'
);
assert.equal(
  checkIsValidElementType(forwardRefComponent),
  true,
  'checkIsValidElementType helper must return true for forwardRef component'
);

// 4. React 17 forwardRef element identification
const forwardRefElement = createSyntheticForwardRefElement(forwardRefComponent, {
  label: 'contract-test-label',
});

assert.equal(
  isForwardRef(forwardRefElement),
  true,
  'isForwardRef must return true for React 17 forwardRef elements'
);
assert.equal(
  checkIsForwardRef(forwardRefElement),
  true,
  'checkIsForwardRef helper must return true for React 17 forwardRef elements'
);
assert.equal(
  typeOf(forwardRefElement),
  ForwardRef,
  'typeOf must return ForwardRef symbol for forwardRef elements'
);
assert.equal(
  identifyElementType(forwardRefElement),
  ForwardRef,
  'identifyElementType helper must return ForwardRef symbol'
);

// 5. Distinction from standard elements and other component types
const standardElement = {
  $$typeof: Symbol.for('react.element'),
  type: 'button',
  props: { className: 'btn' },
  key: null,
  ref: null,
};
assert.equal(
  isForwardRef(standardElement),
  false,
  'isForwardRef must return false for standard HTML/DOM elements'
);
assert.notEqual(
  typeOf(standardElement),
  ForwardRef,
  'typeOf on standard elements must not equal ForwardRef'
);

const fragmentElement = {
  $$typeof: Symbol.for('react.element'),
  type: Symbol.for('react.fragment'),
  props: {},
  key: null,
  ref: null,
};
assert.equal(
  isForwardRef(fragmentElement),
  false,
  'isForwardRef must return false for fragment elements'
);

const providerElement = {
  $$typeof: Symbol.for('react.element'),
  type: {
    $$typeof: Symbol.for('react.provider'),
  },
  props: { value: 'context-val' },
  key: null,
  ref: null,
};
assert.equal(
  isForwardRef(providerElement),
  false,
  'isForwardRef must return false for context provider elements'
);

// 6. Non-element and invalid input rejection
assert.equal(isForwardRef(null), false, 'null is not a forwardRef element');
assert.equal(isForwardRef(undefined), false, 'undefined is not a forwardRef element');
assert.equal(isForwardRef({}), false, 'plain empty object is not a forwardRef element');
assert.equal(isForwardRef('react.forward_ref'), false, 'string primitive is not a forwardRef element');
assert.equal(isForwardRef(12345), false, 'number primitive is not a forwardRef element');
assert.equal(
  isForwardRef(forwardRefComponent),
  false,
  'raw forwardRef component object without element wrapper is not a forwardRef element'
);

assert.equal(typeOf(null), undefined, 'typeOf(null) must return undefined');
assert.equal(typeOf(undefined), undefined, 'typeOf(undefined) must return undefined');
assert.equal(typeOf({}), undefined, 'typeOf({}) must return undefined');
assert.equal(typeOf(forwardRefComponent), undefined, 'typeOf(forwardRefComponent) must return undefined');

console.log('All react-is.ForwardRef contract checks passed successfully.');

오리진 시더

익명