Skip to content

Graphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.

fix(figma): record the published component key on instances

Lum110405e7b99b8164
diff --git a/understand-anything-plugin/packages/core/src/figma/__tests__/parse-document.test.ts b/understand-anything-plugin/packages/core/src/figma/__tests__/parse-document.test.ts
index 9010c95b..45309693 100644
--- a/understand-anything-plugin/packages/core/src/figma/__tests__/parse-document.test.ts
+++ b/understand-anything-plugin/packages/core/src/figma/__tests__/parse-document.test.ts
@@ -19,6 +19,7 @@ const doc: FigmaDocument = {
] },
],
},
+ components: { "2:1": { key: "COMP_KEY_GUID", name: "Primary", componentSetId: "2:0" } },
};
describe("parseDocument", () => {
@@ -44,6 +45,15 @@ describe("parseDocument", () => {
expect(screen.figmaMeta?.dimensions?.width).toBe(375);
expect(screen.figmaMeta?.fileKey).toBe("ABC123");
});
+ it("records the published component key (not the local node id) on instances", () => {
+ const inst = nodes.find((n) => n.id === "instance:1:2")!;
+ expect(inst.figmaMeta?.componentKey).toBe("COMP_KEY_GUID");
+ });
+ it("omits componentKey when the components map has no entry", () => {
+ const bare: FigmaDocument = { ...doc, components: {} };
+ const inst = parseDocument(bare, "ABC123").nodes.find((n) => n.id === "instance:1:2")!;
+ expect(inst.figmaMeta?.componentKey).toBeUndefined();
+ });
it("emits validateGraph-ready nodes (summary/tags/complexity present)", () => {
expect(nodes.every((n) => n.summary && n.tags.length > 0 && n.complexity)).toBe(true);
});
diff --git a/understand-anything-plugin/packages/core/src/figma/parse/parse-document.ts b/understand-anything-plugin/packages/core/src/figma/parse/parse-document.ts
index a1affb0c..4ec55935 100644
--- a/understand-anything-plugin/packages/core/src/figma/parse/parse-document.ts
+++ b/understand-anything-plugin/packages/core/src/figma/parse/parse-document.ts
@@ -33,7 +33,10 @@ export function parseDocument(doc: FigmaDocument, fileKey: string): { nodes: Gra
if (child.type === "INSTANCE") {
const inst = mkNode("instance", child.id, child.name, {
fileKey, nodeId: child.id, figmaType: "INSTANCE",
- componentKey: child.componentId,
+ // The global published key (GUID) from the document's components
+ // map — child.componentId is only a file-local node id, already
+ // captured by the instance_of edge below.
+ componentKey: child.componentId ? doc.components?.[child.componentId]?.key : undefined,
prototypeTargets: child.transitionNodeID ? [child.transitionNodeID] : undefined,
});
add(inst);