Issue applying max-width and max-height properties for text layers in auto-layout using plugin API

I’m developing a Figma plugin that pastes frames onto the canvas using the Plugin API. The frames are structured in JSON format and include nested auto-layout frames with text layers inside them. These text layers are set to “hug” content with specified max-height and max-width properties.

When pasting the frames, all elements are translated and positioned correctly. The text layers are nested within the auto-layout frames and have the layout value set to “hug.” However, the max-width and max-height properties are not being applied as expected.

The Figma app console displays the following error:
“Error applying maxHeight: Error: in set_maxHeight: Can only set maxHeight on auto layout nodes and their children.”

Has anyone else encountered similar issues or found a solution to this? Could this be a bug or a limitation within the Plugin API?

The frames are structured in JSON format

Is it possible that when you’re iterating through the keys of the JSON, you’re setting maxHeight before applying auto-layout to the frame?

For example, the below code will fail, but if you switch the order of the last 2 lines, then it works.

const frame = figma.createFrame()
frame.maxHeight = 100
frame.layoutMode = 'VERTICAL'
1 Like

Thanks a lot James. Issue was indeed that maxHeight needed to be set after initial frame creation.