Skip to content

AI-native design editor. Open-source Figma alternative.

fix(automation): load fonts before scoped layout

Danila Poyarkov8a5daa7472c3
diff --git a/packages/core/src/editor/layout-runner.ts b/packages/core/src/editor/layout-runner.ts
index 347f136c7..f4496eeba 100644
--- a/packages/core/src/editor/layout-runner.ts
+++ b/packages/core/src/editor/layout-runner.ts
@@ -39,10 +39,12 @@ export function createLayoutRunner(getGraph: () => SceneGraph) {
async function runMutationWithLayout<T>(
operation: () => T | Promise<T>,
- fallbackId?: string
+ fallbackId?: string,
+ beforeLayout?: (result: T) => Promise<void> | void
): Promise<T> {
const graph = getGraph()
const { result, impact } = await collectSceneMutation(graph, operation)
+ await beforeLayout?.(result)
const scopeIds = compactLayoutScope(impact)
if (scopeIds.length > 0) {
for (const id of scopeIds) runLayoutForNode(id)
diff --git a/packages/core/src/editor/types.ts b/packages/core/src/editor/types.ts
index b3bd664d8..60417b9d0 100644
--- a/packages/core/src/editor/types.ts
+++ b/packages/core/src/editor/types.ts
@@ -177,6 +177,10 @@ export interface EditorContext {
setActiveTool: (tool: Tool) => void
setNavigationPhase: (phase: NavigationPhase, inputAt?: number) => void
runLayoutForNode: (id: string) => void
- runMutationWithLayout: <T>(operation: () => T | Promise<T>, fallbackId?: string) => Promise<T>
+ runMutationWithLayout: <T>(
+ operation: () => T | Promise<T>,
+ fallbackId?: string,
+ beforeLayout?: (result: T) => Promise<void> | void
+ ) => Promise<T>
subscribeToGraph: () => void
}
diff --git a/src/app/automation/bridge/tool-handlers.ts b/src/app/automation/bridge/tool-handlers.ts
index 7dce37bae..70859b146 100644
--- a/src/app/automation/bridge/tool-handlers.ts
+++ b/src/app/automation/bridge/tool-handlers.ts
@@ -23,9 +23,11 @@ export function createAutomationToolHandler(makeFigma: FigmaFactory) {
x: toolArgs.x as number | undefined,
y: toolArgs.y as number | undefined
}),
- target.pageId
+ target.pageId,
+ async (node) => {
+ await ensureGraphFonts(store.graph, [node.id], store.renderer)
+ }
)
- await ensureGraphFonts(store.graph, [result.id], store.renderer)
store.requestRender()
store.flashNodes([result.id])
return {
@@ -51,12 +53,17 @@ export function createAutomationToolHandler(makeFigma: FigmaFactory) {
registerComponentCatalog(store.graph, libraryService)
const figma = makeFigma(store, target.pageId)
const result = def.mutates
- ? await store.runMutationWithLayout(() => def.execute(figma, toolArgs), figma.currentPageId)
+ ? await store.runMutationWithLayout(
+ () => def.execute(figma, toolArgs),
+ figma.currentPageId,
+ async () => {
+ const pageNode = store.graph.getNode(figma.currentPageId)
+ if (pageNode) await ensureGraphFonts(store.graph, pageNode.childIds, store.renderer)
+ }
+ )
: await def.execute(figma, toolArgs)
if (def.mutates) {
- const pageNode = store.graph.getNode(figma.currentPageId)
- if (pageNode) await ensureGraphFonts(store.graph, pageNode.childIds, store.renderer)
store.requestRender()
store.flashNodes(extractNodeIds(result))
}