Should figma.instance, figma.children and figma.nestedProps wait for the layer to also become undefined instead of breaking?
I'm trying to create some docs using figma code connect and some components have a component inside when a variant it's true and when it's false the component disappears and the code connect breaks...
Example:
We have this default variants:
And the layer tree looks like this:
And when we turn Leading variant into false the layer tree looks like this:
I'm trying to get the icon inside these ". Item / Leading Node" using a figma.instance because Icon it's also a "variant"... When i see a component with the Leading=true it work pretty well but when i see a component with Leading=false it break all the code connect of that component...
Here is the code example:
import React from "react"
import figma from "@figma/code-connect"
import { Component } from "@components"
figma.connect(
Component,
"...",
{
props: {
leadingIcon: figma.nestedProps('. Item / Leading Node', {
icon: figma.instance('Icon')
})
},
example: (props) => <Component {...props} leadingIcon={props?.leadingIcon.icon} />,
},
)
Hey! This should be working after a recent change, if you wrap the nestedProps call in a boolean:
props: {
leadingIcon: figma.boolean("Leading", {
true: figma.nestedProps('. Item / Leading Node', { icon: ... })
false: { icon: undefined }
})
}
Not that you'll want to provide a fallback object in the false case
I am going to close this issue but please let us know if you continue to see this issue