CodeSampleX

Exemple

react-is 19.2.8: isContextProvider

Échantillon vérifié pour npm react-is 19.2.8: isContextProvider. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.

sha256:31bdafae31a12bf7c4d039813b1ffa7d461c8a63f29349f4332cbd9746945b7c

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify react-is.isContextProvider in pkg:npm/react-is@19.2.8
Paquets
Symboles
  • react-is.isContextProvider
Créé
2026-09-06T15:22:38Z

Contrat

  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

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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

Seeder d'origine

anonyme