Skip to content

fix: handle null values in Figma prototype file responses#291

Open
BillionClaw wants to merge 2 commits intoGLips:mainfrom
BillionClaw:fix/prototype-null-safety
Open

fix: handle null values in Figma prototype file responses#291
BillionClaw wants to merge 2 commits intoGLips:mainfrom
BillionClaw:fix/prototype-null-safety

Conversation

@BillionClaw
Copy link
Copy Markdown

Problem

When accessing Figma prototype files (URLs with /proto/ format), the MCP server crashes with:

cannot read properties of null (reading 'components')

This occurs because:

  1. The Figma API returns
    null
    for node responses when accessing prototype files or inaccessible branches
  2. The
    parseAPIResponse()
    function in
    design-extractor.ts
    does not handle null values before accessing properties
  3. Both
    GetFileNodesResponse
    and
    GetFileResponse
    paths lack null-safety checks

Fixes #201

Root Cause

In
src/extractors/design-extractor.ts
:

  • Line 58:
    nodeResponse.components
    accessed without checking if
    nodeResponse
    is null
  • Line 68:
    n.document
    accessed without optional chaining
  • Line 74-75:
    data.components
    and
    data.componentSets
    accessed without null checks
  • Line 80:
    data.document.children
    accessed without optional chaining

Changes

Added comprehensive null-safety checks:

  1. Skip null nodeResponses (line 58): Added early return if
    nodeResponse
    is null
  2. Optional chaining for document access (line 70): Changed to
    n?.document
    with proper filter
  3. Null checks for components/componentSets (lines 74-79): Added
    if
    guards before Object.assign
  4. Safe document children access (line 82): Changed to
    data.document?.children?.filter()
    with nullish coalescing to empty array

Verification


  • pnpm type-check
    : No TypeScript errors

  • pnpm test
    : All 11 tests pass (1 skipped)

  • git diff --check
    : No whitespace issues
  • ✅ Changes limited to 1 file:
    src/extractors/design-extractor.ts
    (+11/-4 lines)

Risk/Edge Cases

  • Prototype files: Now handled gracefully by skipping null responses
  • Inaccessible branches: Same fix applies - null responses are filtered out
  • Regular design files: No behavioral change - existing functionality preserved
  • Empty responses: Returns empty
    nodesToParse
    array instead of crashing

Issue Link

Closes #201

Add null checks when iterating over nodeResponses in parseAPIResponse.
Figma API can return null for nodes when accessing prototype files or
inaccessible branches, causing 'Cannot read properties of null' errors.

Fixes GLips#201
Figma prototype files return different API response structures where
components, componentSets, document, and document.children can be null.
This fix adds null-safety checks to prevent 'Cannot read properties of null'
errors when accessing prototype files.

Fixes GLips#201
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Figma Prototype support?

1 participant