CodeSampleX

샘플

react-refresh 0.18.0: getFamilyByID

검증된 샘플 — npm react-refresh 0.18.0: getFamilyByID. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: react-refresh.getFamilyByID returns undefined…

sha256:e9b65e9ce82168f64c86f431018bf6fa327f53e5aea61260f0a4c6ae760dbe0e

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

컨트랙트

  1. react-refresh.getFamilyByID returns undefined for unregistered family IDs
  2. react-refresh.getFamilyByID returns a family object containing current component type when registered
  3. react-refresh.getFamilyByID returns the identical family reference across multiple lookups
  4. react-refresh.getFamilyByID reflects updated component in family.current after registration update and performReactRefresh
  5. react-refresh.getFamilyByID retrieves derived family IDs for wrapped memo and forwardRef components

파일

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

소스 아티팩트 내려받기 (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-refresh.getFamilyByID in pkg:npm/react-refresh@0.18.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/react-refresh@0.18.0
Demonstrate these symbols/APIs:
  - react-refresh.getFamilyByID

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:e034bceab94cb0d587053c30cc3034844eb7254956544940591dbdbd86917d8e","contract":["react-refresh.getFamilyByID returns undefined for unregistered family IDs","react-refresh.getFamilyByID returns a family object containing current component type when registered","react-refresh.getFamilyByID returns the identical family reference across multiple lookups","react-refresh.getFamilyByID reflects updated component in family.current after registration update and performReactRefresh","react-refresh.getFamilyByID retrieves derived family IDs for wrapped memo and forwardRef components"],"goal":"verify react-refresh.getFamilyByID in pkg:npm/react-refresh@0.18.0","kind":"HOW","packages":["pkg:npm/react-refresh@0.18.0"],"schemaVersion":1,"symbols":["react-refresh.getFamilyByID"]},"contractCommand":["node","test/contract.cjs"],"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-refresh@0.18.0"],"schemaVersion":1,"subject":"pkg:npm/react-refresh@0.18.0","symbols":["react-refresh.getFamilyByID"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-react-refresh-getfamilybyid",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-react-refresh-getfamilybyid",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "react-refresh": "0.18.0"
      }
    },
    "node_modules/react-refresh": {
      "version": "0.18.0",
      "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.18.0.tgz",
      "integrity": "sha512-QgT5//D3jfjJb6Gsjxv0Slpj23ip+HtOpnNgnb2S5zU3CB26G/IDPGoy4RJB42wzFE46DRsstbW6tKHoKbhAxw==",
      "license": "MIT",
      "engines": {
        "node": ">=0.10.0"
      }
    }
  }
}
package.json
{
  "name": "sample-react-refresh-getfamilybyid",
  "version": "1.0.0",
  "private": true,
  "description": "verify react-refresh.getFamilyByID in pkg:npm/react-refresh@0.18.0",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "react-refresh": "0.18.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify react-refresh.getFamilyByID in pkg:npm/react-refresh@0.18.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/react-refresh@0.18.0"
  ],
  "symbols": [
    "react-refresh.getFamilyByID"
  ]
}
src/index.js
'use strict';

// Ensure development environment for react-refresh runtime
if (!process.env.NODE_ENV) {
  process.env.NODE_ENV = 'development';
}

const RefreshRuntime = require('react-refresh/runtime');

/**
 * Retrieves the family object for a given ID using react-refresh getFamilyByID.
 * @param {string} id - The identifier of the component family.
 * @returns {object|undefined} The family object { current: Function|object } or undefined.
 */
function getFamilyByID(id) {
  return RefreshRuntime.getFamilyByID(id);
}

/**
 * Registers a component type with an identifier in the react-refresh runtime.
 * @param {Function|object} type - The component function or memo/forwardRef object.
 * @param {string} id - Unique identifier for the component.
 */
function registerComponent(type, id) {
  RefreshRuntime.register(type, id);
}

/**
 * Checks whether a family has been registered for a given ID.
 * @param {string} id - The identifier to check.
 * @returns {boolean} True if family exists.
 */
function hasFamily(id) {
  return RefreshRuntime.getFamilyByID(id) !== undefined;
}

/**
 * Retrieves the current component reference associated with a family ID.
 * @param {string} id - The identifier of the family.
 * @returns {Function|object|undefined} The current component type, or undefined.
 */
function getFamilyCurrent(id) {
  const family = RefreshRuntime.getFamilyByID(id);
  return family ? family.current : undefined;
}

/**
 * Triggers react-refresh to flush pending updates and update family.current.
 * @returns {object|null} Update object with updatedFamilies and staleFamilies.
 */
function performRefresh() {
  return RefreshRuntime.performReactRefresh();
}

module.exports = {
  RefreshRuntime,
  getFamilyByID,
  registerComponent,
  hasFamily,
  getFamilyCurrent,
  performRefresh,
};
test/contract.cjs
'use strict';

const assert = require('node:assert/strict');
const RefreshRuntime = require('react-refresh/runtime');
const {
  getFamilyByID,
  registerComponent,
  hasFamily,
  getFamilyCurrent,
  performRefresh,
} = require('../src/index.js');

async function testContract() {
  // 1. react-refresh.getFamilyByID returns undefined for unregistered family IDs
  assert.strictEqual(RefreshRuntime.getFamilyByID('NonExistentComponent'), undefined);
  assert.strictEqual(RefreshRuntime.getFamilyByID(''), undefined);
  assert.strictEqual(getFamilyByID('AnotherUnknownID'), undefined);
  assert.strictEqual(hasFamily('UnknownID'), false);
  assert.strictEqual(getFamilyCurrent('UnknownID'), undefined);

  // 2. react-refresh.getFamilyByID returns a family object containing current component type when registered
  function Header() {
    return 'header-content';
  }
  RefreshRuntime.register(Header, 'Header#1');

  const familyDirect = RefreshRuntime.getFamilyByID('Header#1');
  assert.ok(familyDirect, 'family object must exist');
  assert.strictEqual(typeof familyDirect, 'object', 'family must be an object');
  assert.strictEqual(familyDirect.current, Header, 'family.current must reference registered component');

  function Footer() {
    return 'footer-content';
  }
  registerComponent(Footer, 'Footer#1');
  const familyHelper = getFamilyByID('Footer#1');
  assert.ok(familyHelper, 'helper getFamilyByID must return family');
  assert.strictEqual(familyHelper.current, Footer, 'family.current must match Footer component');
  assert.strictEqual(hasFamily('Footer#1'), true, 'hasFamily helper must return true');
  assert.strictEqual(getFamilyCurrent('Footer#1'), Footer, 'getFamilyCurrent helper must return Footer');

  // 3. react-refresh.getFamilyByID returns the identical family reference across multiple lookups
  const lookup1 = RefreshRuntime.getFamilyByID('Header#1');
  const lookup2 = RefreshRuntime.getFamilyByID('Header#1');
  assert.strictEqual(lookup1, lookup2, 'repeated getFamilyByID calls must return identical object reference');
  assert.strictEqual(getFamilyByID('Footer#1'), familyHelper, 'helper lookup must return identical reference');

  // 4. react-refresh.getFamilyByID reflects updated component in family.current after registration update and performReactRefresh
  function HeaderUpdated() {
    return 'header-content-v2';
  }
  RefreshRuntime.register(HeaderUpdated, 'Header#1');
  // Before refresh is flushed, family.current holds previous version
  assert.strictEqual(familyDirect.current, Header, 'family.current stays on previous version before performReactRefresh');

  const refreshResult = RefreshRuntime.performReactRefresh();
  assert.ok(refreshResult, 'performReactRefresh must return refresh update object');
  assert.strictEqual(familyDirect.current, HeaderUpdated, 'family.current must update to new component version after refresh');
  assert.strictEqual(RefreshRuntime.getFamilyByID('Header#1'), familyDirect, 'family reference must remain stable across updates');

  function FooterUpdated() {
    return 'footer-content-v2';
  }
  registerComponent(FooterUpdated, 'Footer#1');
  performRefresh();
  assert.strictEqual(getFamilyCurrent('Footer#1'), FooterUpdated, 'getFamilyCurrent must return updated Footer component');

  // 5. react-refresh.getFamilyByID retrieves derived family IDs for wrapped memo and forwardRef components
  const REACT_MEMO_TYPE = Symbol.for('react.memo');
  const REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');

  function BaseButton(props) {
    return props.label;
  }
  const MemoButton = {
    $$typeof: REACT_MEMO_TYPE,
    type: BaseButton,
  };
  RefreshRuntime.register(MemoButton, 'MemoButton');

  const memoFamily = RefreshRuntime.getFamilyByID('MemoButton');
  const innerMemoFamily = RefreshRuntime.getFamilyByID('MemoButton$type');
  assert.ok(memoFamily, 'memo component family must exist');
  assert.strictEqual(memoFamily.current, MemoButton, 'memo family.current must reference MemoButton');
  assert.ok(innerMemoFamily, 'inner memo component family must exist with $type suffix');
  assert.strictEqual(innerMemoFamily.current, BaseButton, 'inner memo family.current must reference BaseButton');

  function BaseInput(props, ref) {
    return null;
  }
  const ForwardRefInput = {
    $$typeof: REACT_FORWARD_REF_TYPE,
    render: BaseInput,
  };
  registerComponent(ForwardRefInput, 'ForwardRefInput');

  const forwardRefFamily = getFamilyByID('ForwardRefInput');
  const innerRenderFamily = getFamilyByID('ForwardRefInput$render');
  assert.ok(forwardRefFamily, 'forwardRef family must exist');
  assert.strictEqual(forwardRefFamily.current, ForwardRefInput, 'forwardRef family.current must reference ForwardRefInput');
  assert.ok(innerRenderFamily, 'inner render family must exist with $render suffix');
  assert.strictEqual(innerRenderFamily.current, BaseInput, 'inner render family.current must reference BaseInput');

  console.log('Contract assertions verified successfully.');
}

testContract().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

오리진 시더

익명