code-connect icon indicating copy to clipboard operation
code-connect copied to clipboard

Template API V2: `findLayers` doesn't work with `path`

Open sheila-semrush opened this issue 2 months ago • 1 comments

Hi everyone,

I can't get findLayers() to work with the path prop, even though the docs say that it should work.

Image Image

I'm using Template API V2.

instance.findLayers((child) => true) works fine

instance.findConnectedInstances((child) => true, { path: ['parentLayerName'], }) also works fine

but just calling instance.findLayers((child) => true, { path: ['parentLayerName'] }) or even instance.findLayers((child) => true, { path: [] }) immediately gets me an error, even before using the result in any way: Image

Am I doing something wrong, or is there a bug in findLayers, or maybe it's described incorrectly in the docs and doesn't actually accept path?

sheila-semrush avatar Oct 10 '25 19:10 sheila-semrush

After some digging, it seems that text objects just don't have a path property, only instances have it. Which means that nor findLayers, neither findText can work with the path parameter.

Here's an example of a text object from a raw figma object:

{
  "name": "title",
  "type": "TEXT",
  "textContent": "Card Title"
}

And here's an example of an instance:

{
  "properties": {
    ...
  },
  "name": "Info",
  "children": [],
  "type": "INSTANCE",
  "symbolId": "52262:239602",
  "path": [
    "Card.Header",
    "Flex (heading)",
    "Card.Title",
    "Info icon with tooltip (Informer)"
  ],
  "__properties__": {}
}

sheila-semrush avatar Oct 27 '25 20:10 sheila-semrush