CodeSampleX

Sample

react-refresh 0.18.0: getFamilyByType

Verified sample for npm react-refresh 0.18.0: getFamilyByType. The contract ran on node 22 · linux debian/x64 · docker and passed.

sha256:6b1bb9a000514f669de1bb4ee2f537c5ab1f9b35b0ba915e6959ba24b9e84c32

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify react-refresh.getFamilyByType in pkg:npm/react-refresh@0.18.0
Packages
Symbols
  • react-refresh.getFamilyByType
Environment
node 22.23.2
Created
2026-09-06T12:50:03Z

Contract

  1. getFamilyByType returns undefined for an unregistered component type
  2. getFamilyByType returns a family object containing current property for a registered component type
  3. getFamilyByType returns the identical family reference for an updated component type registered with the same id
  4. getFamilyByType returns distinct family references for component types registered with different ids
  5. getFamilyByType returns undefined when called with null, undefined, or primitive values

Files

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

Download the source artifact (tar.gz)

Source

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.getFamilyByType 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.getFamilyByType
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:5b2f7382431638c0037dac065233a63b74dda1a806d9a663a14a9fc2cac99501","constraints":{"executionContext":"node"},"contract":["getFamilyByType returns undefined for an unregistered component type","getFamilyByType returns a family object containing current property for a registered component type","getFamilyByType returns the identical family reference for an updated component type registered with the same id","getFamilyByType returns distinct family references for component types registered with different ids","getFamilyByType returns undefined when called with null, undefined, or primitive values"],"goal":"verify react-refresh.getFamilyByType in pkg:npm/react-refresh@0.18.0","kind":"HOW","packages":["pkg:npm/react-refresh@0.18.0"],"schemaVersion":1,"symbols":["react-refresh.getFamilyByType"]},"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-refresh@0.18.0"],"schemaVersion":1,"subject":"pkg:npm/react-refresh@0.18.0","symbols":["react-refresh.getFamilyByType"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-react-refresh-get-family-by-type",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-react-refresh-get-family-by-type",
      "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-get-family-by-type",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for react-refresh@0.18.0",
  "license": "MIT-0",
  "dependencies": {
    "react-refresh": "0.18.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify react-refresh.getFamilyByType in pkg:npm/react-refresh@0.18.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/react-refresh@0.18.0"
  ],
  "symbols": [
    "react-refresh.getFamilyByType"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const refreshRuntimeModule = require("react-refresh/runtime");

const RefreshRuntime =
  refreshRuntimeModule && typeof refreshRuntimeModule === "object" && "default" in refreshRuntimeModule
    ? refreshRuntimeModule.default
    : refreshRuntimeModule;

/**
 * Returns the family object associated with a given component type, or undefined if not registered.
 *
 * @param {Function|object} type - The component function or object
 * @returns {object|undefined}
 */
function getFamilyByType(type) {
  return RefreshRuntime.getFamilyByType(type);
}

/**
 * Registers a component type with a persistent identifier for Fast Refresh.
 *
 * @param {Function|object} type - The component function or object
 * @param {string} id - Persistent identifier for the component family
 */
function register(type, id) {
  RefreshRuntime.register(type, id);
}

module.exports = {
  RefreshRuntime,
  getFamilyByType,
  register
};
test/contract.mjs
import assert from "node:assert/strict";
import { createRequire } from "node:module";

const require = createRequire(import.meta.url);
const rawRuntime = require("react-refresh/runtime");
const { RefreshRuntime, getFamilyByType, register } = require("../src/index.js");

// Contract 1: getFamilyByType returns undefined for an unregistered component type
{
  function UnregisteredComponent() {
    return "unregistered";
  }

  assert.equal(getFamilyByType(UnregisteredComponent), undefined);
  assert.equal(rawRuntime.getFamilyByType(UnregisteredComponent), undefined);
}

// Contract 2: getFamilyByType returns a family object containing current property for a registered component type
function ComponentA() {
  return "ComponentA";
}
{
  register(ComponentA, "ComponentA");

  const familyA = getFamilyByType(ComponentA);
  assert.notEqual(familyA, undefined);
  assert.equal(typeof familyA, "object");
  assert.equal(familyA.current, ComponentA);

  const rawFamilyA = rawRuntime.getFamilyByType(ComponentA);
  assert.equal(rawFamilyA, familyA);
}

// Contract 3: getFamilyByType returns the identical family reference for an updated component type registered with the same id
function ComponentA_v2() {
  return "ComponentA_v2";
}
{
  register(ComponentA_v2, "ComponentA");

  const familyA_v2 = getFamilyByType(ComponentA_v2);
  const familyA = getFamilyByType(ComponentA);

  assert.notEqual(familyA_v2, undefined);
  assert.equal(familyA_v2, familyA);
}

// Contract 4: getFamilyByType returns distinct family references for component types registered with different ids
function ComponentB() {
  return "ComponentB";
}
{
  register(ComponentB, "ComponentB");

  const familyB = getFamilyByType(ComponentB);
  const familyA = getFamilyByType(ComponentA);

  assert.notEqual(familyB, undefined);
  assert.notEqual(familyB, familyA);
  assert.equal(familyB.current, ComponentB);
}

// Contract 5: getFamilyByType returns undefined when called with null, undefined, or primitive values
{
  assert.equal(getFamilyByType(null), undefined);
  assert.equal(getFamilyByType(undefined), undefined);
  assert.equal(getFamilyByType(0), undefined);
  assert.equal(getFamilyByType(42), undefined);
  assert.equal(getFamilyByType(""), undefined);
  assert.equal(getFamilyByType("ComponentA"), undefined);
  assert.equal(getFamilyByType(true), undefined);
  assert.equal(getFamilyByType(Symbol("comp")), undefined);
}

console.log("All react-refresh.getFamilyByType contract tests passed successfully.");

Origin Seeder

anonymous