// PATTERN TIER: fixture — scaffolding that pins a bug or drives the // runtime. Do not copy from this file. Tiers: packages/patterns/index.md /** * Test Pattern for Superstition #30 * * Tests whether fetchJson() can be dynamically instantiated inside .map() * * Claim: * - fetchJson() calls cannot be created dynamically inside .map() or reactive callbacks * - Framework requires fetchJson to be statically defined at pattern evaluation time * - Dynamic instantiation causes "Frame mismatch" errors or undefined results * * This pattern tests: * 1. Static fetchJson at top level (control - should work) * 2. fetchJson inside .map() with expression callback (claimed to fail) */ import { computed, Default, fetchJson, NAME, pattern, UI } from "commonfabric"; interface Repo { id: string; name: string; } interface GitHubRepoStats { stargazers_count?: number; } interface InputSchema { repos: | Repo[] | Default<[ { id: "1"; name: "react" }, { id: "2"; name: "vue" }, { id: "3"; name: "angular" }, ]>; } export interface Input { repos: Repo[]; } export default pattern(({ repos }) => { // Approach 1: Static fetchJson at top level (control - should work) // Uses computed URL that changes based on first repo const staticUrl = computed(() => repos[0] ? `https://api.github.com/repos/facebook/${repos[0].name}` : "" ); const staticFetch = fetchJson<{ stargazers_count?: number }>({ url: staticUrl, }); // Approach 2: fetchJson inside .map() - expression callback (no block syntax) // This is claimed to fail with frame mismatch or return undefined const dynamicFetches = repos.map((repo) => fetchJson<{ stargazers_count?: number }>({ url: computed(() => `https://api.github.com/repos/facebook/${repo.name}`), }) ); // Display results const staticResult = computed(() => staticFetch.pending ? "Loading..." : staticFetch.error ? `Error: ${staticFetch.error}` : staticFetch.result ? `Stars: ${staticFetch.result.stargazers_count ?? "N/A"}` : "No data" ); return { [NAME]: "Test #30: fetchJson Dynamic Instantiation", [UI]: (

Superstition #30 Test: fetchJson Dynamic Instantiation

Claim Being Tested:

  • fetchJson() cannot be created inside{" "} .map()
  • Framework requires static allocation at pattern body top level
  • Dynamic instantiation causes frame mismatch or undefined results
{/* Static fetchJson (Control) */}

1. Static fetchJson (Control)

fetchJson at top level with computed URL
URL: {staticUrl}
Result: {staticResult}
Pending:{" "} {computed(() => String(staticFetch.pending))}
{/* Dynamic fetchJson */}

2. Dynamic fetchJson (Test)

fetchJson inside .map() callback
{dynamicFetches.map((fetch, index) => (
Repo {index + 1}:
Pending: {computed(() => String(fetch.pending))} {" | "} Error:{" "} {computed(() => fetch.error ? String(fetch.error) : "none")} {" | "} Result: {computed(() => fetch.result ? `Stars: ${fetch.result.stargazers_count ?? "N/A"}` : "No data" )}
))}

Expected Behavior (if superstition is TRUE):

  • Static:{" "} Should work - shows star count
  • Dynamic:{" "} Should FAIL - undefined, error, or frame mismatch

If superstition is FALSE:{" "} Both should show star counts.

Test Repos:

    {repos.map((repo, index) => (
  • {repo.name} (id: {repo.id})
  • ))}
), repos, }; });