Skip to main content
Jul 27, 2023 9:56 AM UTC
Solved

Text styles sometimes have undefined parents

I was trying to find all text nodes using a given text style and sort them according to the pages they’re in. I was able to find the nodes using style.consumers and find the page name & ids for some of these styles with this custom function below:

However, for some of the text nodes, findPage() returns undefined instead. This is strange because:

  • i can locate the text nodes in my Figma File
  • the text nodes are all using local styles
  • they aren’t children of any instances whose components are soft-deleted

Does anyone know why this is happening? If so, what would be a good solution/alternate approach?

This topic has been closed for replies.
Zack_HongSolution
Jul 28, 2023 1:50 AM UTC

Fixed it by telling it to return when calling itself recursively

ie return findParent(node.parent) instead of just findParent(node.parent)

TLDR didn’t write my recursive function properly, needed to explicitly tell its recursive call to return its value so that its return value will propagate back up to the first call of findParent() in the recursion.

1 reply

Zack_HongAuthorSolution
Jul 28, 2023 1:50 AM UTC

Fixed it by telling it to return when calling itself recursively

ie return findParent(node.parent) instead of just findParent(node.parent)

TLDR didn’t write my recursive function properly, needed to explicitly tell its recursive call to return its value so that its return value will propagate back up to the first call of findParent() in the recursion.