Skip to main content
Solved

Text styles sometimes have undefined parents

  • July 27, 2023
  • 1 reply
  • 226 views

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?

Best answer by Zack_Hong

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.

View original
This topic has been closed for replies.

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.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings