示例
react-is 19.2.8: isContextProvider
已验证示例 — npm react-is 19.2.8: isContextProvider. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: isContextProvider is exported as a function from…
sha256:31bdafae31a12bf7c4d039813b1ffa7d461c8a63f29349f4332cbd9746945b7c
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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
契约
- 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
文件
- NOTES.md
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
源代码
# 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.
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.
{"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"}
{
"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"
}
}
}
{
"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"
}
{
"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"
]
}
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,
};
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.');
原始种子者
匿名