Messaging
How messaging works
The plugin UI can't directly access Figma. Instead, it sends messages to the plugin process, which performs the Figma action and optionally sends a result back.
Defining messages
Messages are defined in packages/common/src/networkSides.ts. Each side declares what messages it listens for:
Handling messages in the plugin
In apps/design-plugin/src/plugin/plugin.network.ts, register handlers:
Sending messages from the UI
In packages/ui/src/app.tsx:
Key rules
emit()sends a message without waiting for a responserequest()sends a message and waits for the handler's return value- Message parameters must be simple data (strings, numbers, objects) — no functions or DOM elements
- If a handler is
async, the return type is automatically wrapped in aPromise