bridge
bridge copied to clipboard
Codegen: TEXT nodes fail at execute time when the DS does not use Inter — characters set before text style on default font "Inter Regular"
Summary
bridge-ds compile (7.3.1, console transport) emits, for every TEXT node:
var text_title = figma.createText();
text_title.name = "Title";
text_title.characters = "Connexion"; // ← Rule 12: characters FIRST
await text_title.setTextStyleIdAsync(style_text_heading_2xl.id);
A freshly created text node uses Figma's default font Inter Regular. Writing characters before the text style is applied therefore requires Inter Regular to be loaded — but the preload chunk only loads the fonts listed in the scene graph fonts array (derived from the $text/ styles actually used). On a design system that does not use Inter at all, execution fails on the first TEXT node:
Error: in set_characters: Cannot write to node with unloaded font "Inter Regular".
Please call figma.loadFontAsync({ family: "Inter", style: "Regular" }) and await the returned promise first.
Reproduction
- DS whose text styles are all in Figtree (no Inter anywhere).
- Scene graph with one TEXT node using
$text/Heading/2xl;fonts: [{ "family": "Figtree", "style": "SemiBold" }]. bridge-ds compile→ exit 0.figma_execute(preload)→ ok.figma_execute(build-0)→ the error above; a partial root frame is left on the canvas.
Workaround
Add { "family": "Inter", "style": "Regular" } to fonts in the scene graph. Works, but it is invisible to the author and unrelated to the design.
Proposal (either)
- Codegen: always emit
await figma.loadFontAsync({ family: "Inter", style: "Regular" })in the preload chunk (it is the Plugin API default font — a well-known gotcha), or - Codegen: apply
setTextStyleIdAsyncbefore settingcharacters(the style's font is already loaded fromfonts), so the default font is never touched. Rule 12 ("characters first") is abouttextAutoResize/sizing, which can still be applied after both.
Happy to send a PR for option 1 if you prefer it.