I’m working with Figma’s API and wondering about a couple of things regarding component management.
First question - can I loop through all the mainComponents
in a file without needing to create an instance of each component in my current document? I want to access the master components directly.
Second question is about component identifiers. When I make changes to a component, does its unique ID stay the same? And more importantly, if multiple people or projects use the same component library, will they all see the same ID for each component?
I’m trying to build a tool that tracks component usage across different files, so understanding how these identifiers work is pretty important for my workflow.
I’ve been building similar tooling and can confirm what you’re after is definitely doable. For accessing main components directly, you can iterate through the document tree using figma.root.children
and recursively search for nodes where node.type === 'COMPONENT'
. This gives you the master components without needing instances floating around in your working file. Regarding component IDs, they’re globally unique and persistent across the entire Figma ecosystem. Once a component gets an ID, it keeps that identifier through modifications, renames, and even when published to libraries. This consistency is exactly what makes cross-file tracking possible. I’ve verified this behavior across multiple team libraries and the IDs remain stable, which sounds perfect for your use case of tracking component usage across different files.
totally! you can loop through mainComponents without instances - just use figma.root.findAll(node => node.type === 'COMPONENT')
to grab them. as for IDs, they stay the same even after changes, and everyone sees the same ID if they’re using the same library. super handy for your tool!
From my experience working with Figma’s plugin API, you can access main components through figma.currentPage.findAll()
or traverse the entire document structure if needed. The key difference from what others mentioned is that you might want to consider using figma.getNodeById()
when you already have component IDs stored, which can be more efficient for tracking purposes. Regarding ID persistence, I can confirm they remain constant across edits and library updates. However, one thing to watch out for is when components get deleted and recreated - they’ll receive new IDs even if they appear identical. This happened to me when refactoring a design system and broke some of my tracking logic initially. For cross-file tracking, the component IDs are indeed universal, but you’ll need proper API permissions to access files outside your current scope. Make sure to handle cases where team members might have different access levels to the same library files.