# Prepare for Figma Export: ID Injection Workflow
**Version**: 1.0
**Last Updated**: January 21, 2026
**Purpose**: Temporarily add OBJECT IDs to HTML for Figma MCP export
**Direction**: Code → Figma (with temporary ID injection)
---
## Overview
This workflow enables exporting code to Figma via the html.to.design MCP server **without permanently adding IDs to production code**. The agent temporarily injects OBJECT IDs from specifications during export, then removes them afterward.
### The Problem This Solves
- ✅ **Production code stays clean** - No unnecessary IDs cluttering components
- ✅ **Figma layers get proper names** - OBJECT IDs from specifications used for layer naming
- ✅ **Specification mapping maintained** - Clear connection between specs, code, and Figma
- ✅ **Accessibility preserved** - No misuse of `aria-label` for layer naming
- ✅ **Flexible workflow** - Works for early prototypes and production code
### When to Use This Workflow
Use this workflow when:
- Exporting early prototypes that don't have IDs yet
- Exporting from browser preview for quick design review
- Sending production code to Figma without modifying source files
- Testing visual iterations in Figma before committing to code changes
---
## Choosing Your Export Method
There are **two methods** for exporting to Figma, each with different capabilities:
| Feature | **Method 1: MCP Server** | **Method 2: Browser Extension** |
|---------|-------------------------|--------------------------------|
| **Automation** | ✅ Fully automated | ⚠️ Manual capture required |
| **File Modification** | ✅ No files modified | ⚠️ Temporary aria-labels added to source |
| **Multiple Viewports** | ❌ One viewport at a time | ✅ Mobile, tablet, desktop simultaneously |
| **Responsive Testing** | ❌ Limited | ✅ True responsive capture |
| **Speed** | ✅ Instant | ⚠️ Requires browser interaction |
| **Safety** | ✅ Zero risk (no file changes) | ⚠️ Must remember to remove aria-labels |
| **Best For** | Quick single-page exports | Responsive design documentation |
### Recommendation
**Use MCP Server (Method 1) when:**
- You need a quick export for design review
- You're exporting a single viewport
- You want zero risk of modifying source files
**Use Browser Extension (Method 2) when:**
- You need multiple viewport captures (mobile/tablet/desktop)
- You're documenting responsive behavior
- You want to see how design adapts across breakpoints
---
## Core Principle: Temporary aria-label Injection
**The Strategy:**
1. **Read** the component code (without aria-labels)
2. **Load** OBJECT IDs from specification
3. **Generate** temporary HTML with `aria-label` attributes matching OBJECT IDs
4. **Export** to Figma via MCP (one page at a time)
5. **Discard** temporary HTML (never save to files)
**Result:** Figma layers get named from `aria-label` values, production code stays clean.
**Why aria-label for Figma?**
- The html.to.design MCP server uses `aria-label` attributes to name Figma layers
- These are temporary - only added during export, never saved to source files
- Production code keeps proper accessibility practices (aria-labels only where needed)
---
## Phase 1: Identify Export Target
### Step 1.1: Determine What to Export
**User Request Examples:**
- "Export the sign-in page to Figma"
- "Send the CTA button states to Figma for design review"
- "I want to iterate on the hero section spacing in Figma"
**Extract:**
- Component/page name
- File path (if provided)
- Purpose (design review, state documentation, visual iteration)
---
### Step 1.2: Locate Source Code
**Search Strategy:**
```
1. Check if user provided file path
2. Search in components/ directory
3. Search in app/ directory
4. Search in docs/ for prototypes
```
**Decision Point:**
- ✅ Source found → **Continue to Phase 2**
- ❌ Source not found → **Ask user for clarification**
---
## Phase 2: Load Specification OBJECT IDs
### Step 2.1: Search for Specification
**Search Locations (priority order):**
1. `docs/C-Scenarios/` - Scenario specifications
2. `docs/D-Design-System/` - Component specifications
3. Project root - Any related markdown files
**Search Method:**
```
Use grep_search or find_by_name to locate:
- Files containing component/page name
- Files with "OBJECT ID" references
- Specification markdown files
```
---
### Step 2.2: Extract OBJECT IDs
**What to Extract:**
```markdown
From specification file:
#### Hero Section CTA Button
**OBJECT ID**: `start-hero-cta`
**CSS Class**: `.btn-cta-primary`
Extract:
- OBJECT ID: start-hero-cta
- Component: Hero Section CTA Button
- CSS Class: btn-cta-primary
```
**Create ID Mapping:**
```javascript
{
"start-hero-cta": {
"cssClass": "btn-cta-primary",
"selector": "button.btn-cta-primary",
"type": "button"
},
"start-hero-headline": {
"cssClass": "hero-headline",
"selector": "h1.hero-headline",
"type": "heading"
}
}
```
---
### Step 2.3: Handle Missing Specifications
**If no specification found:**
**Option A: Generate IDs from Code Structure**
```
Analyze component structure:
- Extract CSS class names
- Identify semantic elements
- Generate OBJECT IDs following project convention
Pattern: {page}-{section}-{element}
Example: start-hero-cta, start-hero-headline
```
**Option B: Ask User for Guidance**
```
⚠️ No specification found for {component-name}
I can:
1. Generate temporary IDs based on code structure
2. Create a specification first (recommended)
3. Use CSS class names as IDs
Which approach would you prefer?
```
---
## Phase 3: Generate Temporary HTML with IDs
### Step 3.1: Read Source Code
**For React/TSX Components:**
```tsx
// Original component (no IDs)
export function LandingHero() {
return (
Every walk. on time. Every time.
)
}
```
---
### Step 3.2: Map OBJECT IDs to Elements
**Mapping Strategy:**
```
Match by CSS class:
.hero-section → aria-label="start-hero-section"
.hero-content → aria-label="start-hero-content"
.hero-headline → aria-label="start-hero-headline"
.btn-cta-primary → aria-label="start-hero-cta"
Match by semantic element + context:
in hero → aria-label="start-hero-section"