Skip to main content
Question

Error when changing value of imported variant?

  • May 2, 2023
  • 7 replies
  • 626 views

Lucas_Miqueias

I’m getting this error when changing the status of a variant from true to false with the setProperties function

`Uncaught Error: “Unexpected: _dirty” in ~SymbolOverrider (FGSymbolOverrider.cpp)

Uncaught Error: “Unexpected: scene()->mutationsAreDisallowed()” in set (FGNode.cpp)

Uncaught Error: “It shouldn’t even be possible for a read-only scene graph observer to recurse.” in handleObserverEvent (FGSceneGraphEvent.h)
`

My code is like this

[image]

This topic has been closed for replies.

7 replies

jak_e
Figmate
  • Figmate
  • 28 replies
  • May 3, 2023

can you provide the code where component is defined?


Lucas_Miqueias

Hey Jack, the main code is right below. But the error is not in the component. This error only happens when I change the Header variant in the Box

import { on, showUI, once } from '@create-figma-plugin/utilities'

import { ResizeWindowHandler } from './types'

export default function () {
  on<ResizeWindowHandler>(
    'RESIZE_WINDOW',
    function (windowSize: { width: number; height: number }) {
      const { width, height } = windowSize
      figma.ui.resize(width, height)
    } 
  )

  function handleSubmit ( valueInput: any, stateComponent: any, valueButton: any) {

    interface Button {
      value: string | boolean,
      count: number
    }

    interface Trackers {
      value: string,
      type: string
    }

    const trackers: Trackers[] = [];

    const buttons: Button[] = [];

    valueButton.forEach((i: { value: string, count: number; }) =>{
      if (valueButton.length === 0 && valueButton[0].value.length === 0) {
        const newButton: Button = {
          value: false,
          count: 0
        };
      } else {
        const newButton: Button = {
          value: `${i.value}`,
          count: i.count
        };
        buttons.push(newButton)
      }
    })

    interface Body {
      header: string;
      body: string;
      footer: string;
    }

    interface Component {
      plataforma: string;
      tipo: string;
      corpo: Body;
      botoes: any[];
    }

    const component:Component = {
      plataforma: stateComponent.plataforma,
      tipo: stateComponent.tipo,
      corpo: {
        header: valueInput.header,
        body: valueInput.content,
        footer: valueInput.footer
      },
      botoes: buttons
    };
    
    (async () => {

      let importComponent = await figma.importComponentByKeyAsync('***')
      let instance = importComponent.createInstance()
      let page = figma.root.children[0];    
      page.appendChild(instance);
      
      const nodes = figma.currentPage.findAllWithCriteria({
        types: ['INSTANCE']
      })

      const elementNames: string[] = [
        'Component', 'Header', 'Content', 'Input', 'Rodapé', 'Botões Quickreply'
      ];

      const elements: Record<string, any> = {};

      for (const node of nodes) {
        const index = elementNames.indexOf(node.name);
        if (index !== -1) {
          elements[elementNames[index]] = node;
        }
      }

      const {
        'Component': Component,
        'Header': Header,
        'Content': Box,
        'Input': Content,
        'Rodapé': Footer,
        'Botões Quickreply': BtnQuickReply
      } = elements;

      // INSERT DATA INPUT ON COMPONENT

      Content.setProperties({ 'Text#211:1': component.corpo.body })
      Footer.setProperties({ 'Text#520:0': component.corpo.footer })
      Box.setProperties({ Header : 'true' })

    })();

  }
  on('SUBMIT', handleSubmit)

  showUI({
    width: 440,
    height: 740
  })
}


jak_e
Figmate
  • Figmate
  • 28 replies
  • May 3, 2023

I believe the property name "Header" should be something like "Header#00:0" similar to the Text property names above it. You should be able to find that name in importComponent.componentPropertyDefinitions.

Also, can you confirm, is the Header property a boolean or a string for the component? The only other possible thing I see wrong on that line is if you should be saying:

Box.setProperties({ "Header#0:0": false });

instead of

Box.setProperties({ "Header#0:0": 'false' });

Lucas_Miqueias

Box is an instance of the component. This instance actually has the Header property and the value is a string.

figma2

The expected action happens, but I keep getting an error that looks like figma rendering itself.


jak_e
Figmate
  • Figmate
  • 28 replies
  • May 4, 2023

Oh I see, this is a variant. That naming makes sense then. When you say “the expected action happens” are you saying that the code works but there’s also an error?


Lucas_Miqueias

Exactly, the code works, the component is created and the variant value changed, but the error appears in the console.


jak_e
Figmate
  • Figmate
  • 28 replies
  • May 8, 2023

i dont think this is your fault. other people are reporting it happening in other scenarios we’re looking into it. thanks for bringing this up!