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

Should figma.instance, figma.children and figma.nestedProps wait for the layer to also become undefined instead of breaking?

Open nrenard opened this issue 1 year ago • 1 comments

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: Screenshot 2024-06-24 at 8 27 24 PM

And the layer tree looks like this: Screenshot 2024-06-24 at 8 28 21 PM

And when we turn Leading variant into false the layer tree looks like this: Screenshot 2024-06-24 at 8 29 11 PM


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} />,
  },
)

nrenard avatar Jun 24 '24 23:06 nrenard

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

karlpetersson avatar Oct 02 '24 20:10 karlpetersson

I am going to close this issue but please let us know if you continue to see this issue

tomduncalf-figma avatar Oct 22 '24 09:10 tomduncalf-figma