CodeSampleX

샘플

react-is 19.2.8: isContextProvider

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

sha256:31bdafae31a12bf7c4d039813b1ffa7d461c8a63f29349f4332cbd9746945b7c

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

컨트랙트

  1. isContextProvider is exported as a function from react-is and ContextProvider matches Symbol.for('react.context')
  2. isContextProvider returns true for React elements created with a Context or Context Provider type
  3. isContextProvider returns false for bare Context or Context Provider type objects without an element wrapper
  4. isContextProvider returns false for React Context Consumer elements
  5. isContextProvider returns false for standard DOM elements, Fragment elements, plain component elements, and primitives
  6. typeOf correctly identifies React Context Provider elements as matching the ContextProvider symbol

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

NOTES.md
# react-is isContextProvider in React 19

Verification of `react-is.isContextProvider` in `pkg:npm/react-is@19.2.8`.

## React 19 Context Provider Semantics

In React 19, the internals of Context and element classification underwent significant changes:

1. **Symbol Alignment**:
   - `ContextProvider` in React 19 is `Symbol.for('react.context')`, unifying `<Context>` and `<Context.Provider>`.
   - `ContextConsumer` remains `Symbol.for('react.consumer')`.
   - React elements now carry `$$typeof: Symbol.for('react.transitional.element')` (`Element`).

2. **`isContextProvider` Behavior**:
   - Returns `true` for React 19 elements whose component type is either a Context object or a Context Provider object.
   - Returns `false` for bare Context or Context Provider objects that lack the transitional element wrapper.
   - Returns `false` for Context Consumer elements.
   - Returns `false` for standard DOM elements, Fragment elements, function components, legacy React 18 elements (`Symbol.for('react.element')`), and primitives.

3. **`typeOf` Behavior**:
   - Returns `ContextProvider` (`Symbol.for('react.context')`) for Context Provider elements.
   - Returns `ContextConsumer` (`Symbol.for('react.consumer')`) for Context Consumer elements.
   - Returns `Element` (`Symbol.for('react.transitional.element')`) for standard DOM elements and function components.
   - Returns `undefined` for non-element objects and primitives.
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.isContextProvider in pkg:npm/react-is@19.2.8
Kind: HOW

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

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:e6e3cc3ddfd54d6c5d7153cb2e9a5f7e50286252e3cd7bae0084ce0cb7e23aeb","contract":["isContextProvider is exported as a function from react-is and ContextProvider matches Symbol.for('react.context')","isContextProvider returns true for React elements created with a Context or Context Provider type","isContextProvider returns false for bare Context or Context Provider type objects without an element wrapper","isContextProvider returns false for React Context Consumer elements","isContextProvider returns false for standard DOM elements, Fragment elements, plain component elements, and primitives","typeOf correctly identifies React Context Provider elements as matching the ContextProvider symbol"],"goal":"verify react-is.isContextProvider in pkg:npm/react-is@19.2.8","kind":"HOW","packages":["pkg:npm/react-is@19.2.8"],"schemaVersion":1,"symbols":["react-is.isContextProvider"]},"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@19.2.8"],"schemaVersion":1,"subject":"pkg:npm/react-is@19.2.8","symbols":["react-is.isContextProvider"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-react-is-context-provider",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-react-is-context-provider",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "react-is": "19.2.8"
      }
    },
    "node_modules/react-is": {
      "version": "19.2.8",
      "resolved": "https://registry.npmjs.org/react-is/-/react-is-19.2.8.tgz",
      "integrity": "sha512-s5un28nYxKJw5gvUHyW5PCC28CvBqLu9r3cWgzHT4Vo/5fqqkFcdRYsGcKf50WMPpjjFZS5d76fn3YCo2njKwQ==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-react-is-context-provider",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of react-is.isContextProvider for React 19",
  "type": "module",
  "main": "src/index.mjs",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "react-is": "19.2.8"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify react-is.isContextProvider in pkg:npm/react-is@19.2.8",
  "kind": "HOW",
  "packages": [
    "pkg:npm/react-is@19.2.8"
  ],
  "symbols": [
    "react-is.isContextProvider"
  ]
}
src/index.mjs
import {
  isContextProvider,
  ContextProvider,
  ContextConsumer,
  Element,
  typeOf,
} from 'react-is';

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

/**
 * Identify the React element type symbol of a given object.
 *
 * @param {*} value - The value to inspect.
 * @returns {symbol|undefined} The matched React symbol or undefined.
 */
export function identifyTypeOf(value) {
  return typeOf(value);
}

/**
 * Create a mock React element with the transitional element marker.
 *
 * @param {*} type - The element type.
 * @param {object} [props={}] - Optional props object.
 * @returns {object} Mock React element object.
 */
export function createMockElement(type, props = {}) {
  return {
    $$typeof: Element,
    type,
    props,
    key: null,
    ref: null,
  };
}

/**
 * Create a mock React Context object matching React 19 context structure.
 *
 * @param {*} defaultValue - Initial context default value.
 * @returns {object} Mock Context object.
 */
export function createMockContext(defaultValue = null) {
  const context = {
    $$typeof: ContextProvider,
    _currentValue: defaultValue,
    _defaultValue: defaultValue,
  };
  context.Provider = {
    $$typeof: ContextProvider,
    _context: context,
  };
  context.Consumer = {
    $$typeof: ContextConsumer,
    _context: context,
  };
  return context;
}

export {
  isContextProvider,
  ContextProvider,
  ContextConsumer,
  Element,
  typeOf,
};
test/contract.mjs
import assert from 'node:assert/strict';
import {
  checkIsContextProvider,
  identifyTypeOf,
  createMockElement,
  createMockContext,
  isContextProvider,
  ContextProvider,
  ContextConsumer,
  Element,
  typeOf,
} from '../src/index.mjs';

// 1. Export types and symbols
assert.equal(typeof isContextProvider, 'function', 'isContextProvider should be a function');
assert.equal(typeof checkIsContextProvider, 'function', 'checkIsContextProvider should be a function');
assert.equal(typeof typeOf, 'function', 'typeOf should be a function');
assert.equal(typeof identifyTypeOf, 'function', 'identifyTypeOf should be a function');
assert.equal(typeof ContextProvider, 'symbol', 'ContextProvider should be a symbol');
assert.equal(ContextProvider, Symbol.for('react.context'), 'ContextProvider must match Symbol.for("react.context") in React 19');
assert.equal(ContextConsumer, Symbol.for('react.consumer'), 'ContextConsumer must match Symbol.for("react.consumer")');
assert.equal(Element, Symbol.for('react.transitional.element'), 'Element must match Symbol.for("react.transitional.element") in React 19');

// 2. React Context Provider element detection
const mockContext = createMockContext('default-value');

// In React 19, <Context value={...}> creates an element whose type is the context itself
const directContextElement = createMockElement(mockContext, { value: 'custom-value' });
assert.equal(isContextProvider(directContextElement), true, 'isContextProvider must return true for direct Context element');
assert.equal(checkIsContextProvider(directContextElement), true, 'checkIsContextProvider helper must return true');

// <Context.Provider value={...}> creates an element whose type is context.Provider
const providerElement = createMockElement(mockContext.Provider, { value: 'custom-value' });
assert.equal(isContextProvider(providerElement), true, 'isContextProvider must return true for Context.Provider element');
assert.equal(checkIsContextProvider(providerElement), true, 'checkIsContextProvider helper must return true');

// 3. Rejection of bare Context and Context Provider type objects without element wrapper
assert.equal(isContextProvider(mockContext), false, 'bare Context object is not an element');
assert.equal(isContextProvider(mockContext.Provider), false, 'bare Context.Provider object is not an element');
assert.equal(identifyTypeOf(mockContext), undefined, 'typeOf bare Context object must be undefined');

// 4. Rejection of Context Consumer elements
const consumerElement = createMockElement(mockContext.Consumer, { children: () => null });
assert.equal(isContextProvider(consumerElement), false, 'Context Consumer element must not be identified as ContextProvider');

// 5. Rejection of standard DOM elements, Fragment elements, plain component elements, and primitives
const domElement = createMockElement('div', { className: 'test' });
assert.equal(isContextProvider(domElement), false, 'DOM element must not be identified as ContextProvider');

const fragmentElement = createMockElement(Symbol.for('react.fragment'));
assert.equal(isContextProvider(fragmentElement), false, 'Fragment element must not be identified as ContextProvider');

const plainComponentElement = createMockElement(function TestComponent() { return null; });
assert.equal(isContextProvider(plainComponentElement), false, 'Plain component element must not be identified as ContextProvider');

// Legacy React 18 element format (Symbol.for('react.element'))
const legacy18Element = {
  $$typeof: Symbol.for('react.element'),
  type: {
    $$typeof: Symbol.for('react.provider'),
  },
};
assert.equal(isContextProvider(legacy18Element), false, 'Legacy React 18 element must not be identified as ContextProvider');

// Non-element objects and primitives
assert.equal(isContextProvider({}), false, 'empty object is not a ContextProvider');
assert.equal(isContextProvider(null), false, 'null is not a ContextProvider');
assert.equal(isContextProvider(undefined), false, 'undefined is not a ContextProvider');
assert.equal(isContextProvider('provider'), false, 'string is not a ContextProvider');
assert.equal(isContextProvider(42), false, 'number is not a ContextProvider');
assert.equal(isContextProvider(true), false, 'boolean is not a ContextProvider');
assert.equal(isContextProvider(ContextProvider), false, 'ContextProvider symbol itself is not a ContextProvider element');

// 6. typeOf validation
assert.equal(typeOf(directContextElement), ContextProvider, 'typeOf(directContextElement) must equal ContextProvider symbol');
assert.equal(identifyTypeOf(directContextElement), ContextProvider, 'identifyTypeOf helper must return ContextProvider symbol');
assert.equal(typeOf(providerElement), ContextProvider, 'typeOf(providerElement) must equal ContextProvider symbol');
assert.equal(typeOf(consumerElement), ContextConsumer, 'typeOf(consumerElement) must equal ContextConsumer symbol');
assert.equal(typeOf(plainComponentElement), Element, 'typeOf(plainComponentElement) must equal Element symbol');
assert.equal(typeOf(domElement), Element, 'typeOf(domElement) must equal Element symbol');
assert.equal(typeOf({}), undefined, 'typeOf on non-element must return undefined');

console.log('Contract tests for react-is.isContextProvider (pkg:npm/react-is@19.2.8) passed successfully.');

오리진 시더

익명