fix: handle null values in Figma prototype file responses#291
Open
BillionClaw wants to merge 2 commits intoGLips:mainfrom
Open
fix: handle null values in Figma prototype file responses#291BillionClaw wants to merge 2 commits intoGLips:mainfrom
BillionClaw wants to merge 2 commits intoGLips:mainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
null
for node responses when accessing prototype files or inaccessible branches
parseAPIResponse()
function in
design-extractor.ts
does not handle null values before accessing properties
GetFileNodesResponse
and
GetFileResponse
paths lack null-safety checks
Fixes #201
Root Cause
In
src/extractors/design-extractor.ts
:
nodeResponse.components
accessed without checking if
nodeResponse
is null
n.document
accessed without optional chaining
data.components
and
data.componentSets
accessed without null checks
data.document.children
accessed without optional chaining
Changes
Added comprehensive null-safety checks:
nodeResponse
is null
n?.document
with proper filter
if
guards before Object.assign
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
src/extractors/design-extractor.ts
(+11/-4 lines)
Risk/Edge Cases
nodesToParse
array instead of crashing
Issue Link
Closes #201