Skip to content
FramesField
FIX 12 · VISUAL & 3D CRAFT
raw .md ↗ Verified Dec 1, 2026

Fix Figma MCP Overflow and Hardcoded Hex Sprawl

Direct Fix: Pass targeted Figma selection URLs (?node-id=X-Y), map Tailwind CSS v4 tokens via @theme inline to runtime CSS variables, install Skill 32 (design-tokens-tailwind-v4-skill), and run a 1-line grep gate rejecting arbitrary hex classes before merging.
Exact Error / Visual Signature
Agent output: bg-dr-paper text-dr-850 border-dr-text | Figma MCP timeout / truncated JSON on root file URL | Dark mode stays blinding white
OBSERVED SYMPTOM

You connect Figma MCP to Claude Code or Cursor, paste a Figma file link, and either the MCP tool times out / truncates half the frame, OR the generated Tailwind v4 UI ships 40 hardcoded arbitrary hex classes that completely break dark mode.

TECHNICAL ROOT CAUSE

Three classic design-to-code configuration errors: (1) passing a full multi-page Figma file URL instead of a targeted ?node-id=X-Y selection frame; (2) defining Tailwind v4 tokens inside static @theme instead of runtime @theme inline; (3) omitting a persistent SKILL.md token rulebook and automated hex-ban grep check.

Copy-Paste Verified Fix

Install Tailwind v4 Token Skill + Automated Arbitrary-Hex CI Gate fix-figma-mcp-hex-sprawl.sh
# 1. Install FramesField Tailwind v4 Design Token Contract into Claude Code or Cursor
mkdir -p .claude/skills/design-tokens-tailwind-v4 .cursor/skills/design-tokens-tailwind-v4
curl -fsSL https://framesfield.com/raw/skills/design-tokens-tailwind-v4-skill -o .claude/skills/design-tokens-tailwind-v4/SKILL.md
cp .claude/skills/design-tokens-tailwind-v4/SKILL.md .cursor/skills/design-tokens-tailwind-v4/SKILL.md

# 2. Audit codebase for arbitrary Tailwind hex sprawl (bg-[#...], text-[#...], border-[#...])
grep -rnE '(bg|text|border|ring|fill|stroke)-\[#([0-9a-fA-F]{3,8})\]' src/components src/pages && \
  echo "FAIL: Replace arbitrary hex classes above with semantic @theme inline tokens!" || \
  echo "PASS: Zero arbitrary hex sprawl across src/components and src/pages"

# 3. Verify Figma prompt rule: ALWAYS pass exact selection link with ?node-id=X-Y (never root file URL!)

Before vs. After (Broken Pattern vs. Verified Fix)

Broken · Broken Tailwind v4 Theme & Component (Static @theme + Arbitrary Hex Sprawl)
/* global.css — static @theme bakes hex literals, breaking dark mode! */
@theme { --color-canvas: #F7F7F5; }
/* Hero.astro — arbitrary hex sprawl ignores theme switches completely */
<section class="bg-dr-paper text-dr-850 border-dr-text">...</section>
Verified · Verified Tailwind v4 Runtime Tokens (@theme inline + Semantic Utilities)
/* global.css — runtime custom properties + @theme inline */
:root { --surface-canvas: #F7F7F5; --ink-primary: #111111; }
[data-theme="dark"] { --surface-canvas: #111110; --ink-primary: #F5F5F2; }
@theme inline { --color-canvas: var(--surface-canvas); --color-ink: var(--ink-primary); }
/* Hero.astro — zero hex classes; flips Daylight <-> Darkroom automatically */
<section class="bg-canvas text-ink border-hairline">...</section>

Why this works: Using @theme inline tells Tailwind v4 to preserve var(--surface-canvas) at runtime so theme toggles flip every component from a single CSS variable table.

Under the Hood

Why This Failure Happens in Real Pipelines

A production Figma workspace often contains 15 pages, 200 variants, and thousands of vector nodes. Pointing Figma MCP at the root file URL dumps megabytes of irrelevant JSON into the coding agent’s context window, causing truncation, timeouts, or hallucinated CSS padding. Selecting the exact target section frame in Figma and copying its selection URL (?node-id=123-456) shrinks the MCP payload 95% and surfaces clean Auto-Layout flex/grid constraints verbatim.

Even with exact Figma Variables read cleanly, Tailwind CSS v4 introduces a subtle trap: defining colors inside static @theme { --color-canvas: #F7F7F5; } bakes literal #F7F7F5 strings straight into compiled CSS classes—so toggling [data-theme="dark"] changes NOTHING. Declaring runtime CSS variables inside :root and [data-theme="dark"], then mapping utilities through @theme inline { --color-canvas: var(--surface-canvas); } makes every semantic utility (bg-canvas, text-ink, border-hairline) flip themes instantaneously.

Step-by-Step Resolution & Verification

  1. 01

    Copy the specific Figma frame URL (?node-id=X-Y), never the root file

    Select the single section or component frame in Figma (Shift+L / Copy link to selection) so Figma MCP fetches compact, exact Auto-Layout and Variable definitions.

  2. 02

    Switch static @theme to runtime @theme inline in Tailwind CSS v4

    Define light and dark hex values strictly inside :root and [data-theme="dark"], then map semantic Tailwind utilities (--color-canvas, --color-ink, --color-signal) via @theme inline.

  3. 03

    Run automated arbitrary-hex grep + Playwright 1440px/390px visual QA

    Block any PR introducing bg-[#...] / text-[#...] classes and delegate final visual contrast & mobile-overflow inspection to @ui-design-critic.

Verification Check · Confirm Zero Arbitrary Hex Sprawl + Clean 1440px/390px Playwright Render
grep -rnE '(bg|text|border)-\[#([0-9a-fA-F]{3,8})\]' src/components src/pages || echo "CLEAN: 0 hardcoded Tailwind hex classes"
Expected healthy output:
CLEAN: 0 hardcoded Tailwind hex classes

How to Prevent This Error From Recurring

GUARDRAIL 01

Run @design-handoff-reviewer BEFORE generating component JSX

Auditing the Figma node upfront exposes unmapped variables, missing empty/hover states, and mobile stacking gaps before a single line of CSS is written.

GUARDRAIL 02

Enforce the arbitrary-hex grep check inside pre-commit or CI

A 1-line grep command guarantees zero visual token drift even across rapid multi-agent coding sessions.

GUARDRAIL 03

Keep Figma Variables named identically to CSS semantic tokens

Matching Figma Variable names (surface/canvas, ink/primary, accent/signal) directly to CSS custom properties enables 1-to-1 Pass-1 code generation.

Troubleshooting FAQs

Why does Tailwind CSS v4 static @theme break [data-theme="dark"] mode switching?
In Tailwind v4, static @theme resolves custom values at compile time into hardcoded CSS properties. Switching to @theme inline tells Tailwind to emit var(--your-token) at runtime so CSS overrides under [data-theme="dark"] update every component live.
How do I copy a targeted ?node-id=X-Y URL in Figma?
Click the exact outer section frame on your Figma canvas, right-click -> Copy/Paste as -> Copy link to selection (or press Cmd/Ctrl+L). Confirm the pasted URL ends with ?node-id=123-456.
What if a Figma file uses raw detached colors instead of Figma Variables?
Run @design-handoff-reviewer (Skill 44) first and instruct the coding agent to map every raw hex value to the nearest existing semantic token in src/styles/global.css instead of inventing arbitrary bg-[#...] utilities.
Can I still use arbitrary hex values for one-off UI dead-zone overlays or charts?
Keep semantic design tokens (bg-surface, text-ink, bg-signal, border-hairline) on 100% of UI surfaces and reserve raw hex strictly for standalone SVG chart generators or data-viz palettes.
Which two skills prevent 90% of AI frontend layout regressions?
Pair Skill 32 (design-tokens-tailwind-v4-skill) for strict token compliance with Skill 26 (playwright-visual-qa-mcp-setup) and Skill 35 (@ui-design-critic) for automated 1440px desktop and 390px mobile screenshot audits.
Use this page in AI tools or notes
raw .md