Skip to main content
rob-redbar
Jan 12, 2023 7:15 PM UTC
Question

Promise-based messaging between plugin and ui

Does anyone know of a way to do promise-based messaging between the plugin and the UI? (@Gleb 🙂)

Using the globals:

parent.postMessage(...) → figma.ui.onmessage → figma.ui.postMessage(...) → window.onmessage can lead to spaghetti code… promises would be so much cleaner.

Really only the UI → Plugin direction would be fine, e.g.:

someCoolMessaging.post(type: 'get-some-data', payload: { id: 5 }).then(data => {
    console.log('got some data', data)
})
.catch((error) => {
  console.log('error getting data from plugin')
})
This topic has been closed for replies.

7 replies

Gleb
Power Member
Jan 13, 2023 2:40 AM UTC
rob-redbar
Jan 13, 2023 3:02 AM UTC

figma-messenger seems to be just a type-safe version of 1-way comms, but html<->script I/O seems to have a way to do async/promises. Will try it, thanks!

Michael_Yagudaev
Jan 19, 2023 1:22 AM UTC

I’ve created a library for it, and maybe I should publish it. It is built on top of Utilities — Create Figma Plugin with 3 basic primitives: req, res and subscribe.

I should probably publish it too.

This emit utility will help a lot. Any mechanism that abstracts iframe <=> iframe communication will help too.

In any case, what you are asking is

// ui.js
await Main.drawRect()

// main.js
function drawRect() { 
  const rect = figma.createRect()
  ....
}

From what I’ve seen no other library currently supports this.

Jakub Hajduk
New Member
Mar 11, 2025 3:46 PM UTC

Hello,

in case someone is still looking for an solution to communicate UI and plugin code, I wrote figwire - lightweight, TypeScript-friendly library for seamless communication between Figma plugin and its UI.

 https://www.npmjs.com/package/figwire

Jay Bee
New Participant
Aug 13, 2025 6:13 AM UTC

​@Jakub Hajduk Thank you for your hard work! I loved the API and your code structure. I’ll be using it in my next plugin.

Jay Bee
New Participant
Aug 16, 2025 11:49 AM UTC

Just wanted to report back saying that using Figwire + Zustand gives an incredibly powerful and flexible DX. It’s all promise-based and you can even send messages from the plugin to the UI with ease to be consumed by React. Figma should seriously consider integrating a similar mechanism into the regular workflow. Highly recommended. 🤟

Jakub Hajduk
New Member
Oct 20, 2025 11:33 AM UTC

Awesome to hear that! I’m very glad you liked it. ;).