Skip to content

🐛 Fix NodeChangeProperty not including the 'variant' key#354

Open
Lorenzo-Tr wants to merge 1 commit into
figma:masterfrom
Lorenzo-Tr:master
Open

🐛 Fix NodeChangeProperty not including the 'variant' key#354
Lorenzo-Tr wants to merge 1 commit into
figma:masterfrom
Lorenzo-Tr:master

Conversation

@Lorenzo-Tr
Copy link
Copy Markdown

Add 'variant' to NodeChangeProperty

Problem

The NodeChangeProperty union type is missing 'variant' as a valid value. However, at runtime, when a variant changes on an InstanceNode, the documentchange event does return 'variant' inside the properties array:

{
  "type": "PROPERTY_CHANGE",
  "properties": ["variant"]
}

This means plugin developers cannot check for variant changes in a type-safe way. The only workaround is an unsafe cast:

(change.properties as (NodeChangeProperty | 'variant')[]).includes('variant')

Fix

Added 'variant' to the NodeChangeProperty union type so that variant changes on InstanceNode can be detected without bypassing TypeScript's type system.

Testing

You can verify the fix by listening to document changes and swapping the variant of an InstanceNode in the canvas:

figma.on('documentchange', (event) => {
  for (const change of event.documentChanges) {
    if (
      change.type === 'PROPERTY_CHANGE' &&
      change.properties.includes('variant') // ✅ now valid without casting
    ) {
      console.log('Variant changed on node:', change.node.id)
    }
  }
})

@Lorenzo-Tr
Copy link
Copy Markdown
Author

@rmah-figma Hello, I ping you to know if it could be merge or not ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant