Skip to content

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

Fix text w="fill" exported as w={computed}, add wrap rowGap check

Anton A S8300ebb80781
diff --git a/packages/core/src/render/export-jsx.ts b/packages/core/src/render/export-jsx.ts
index 5d9eb411c..a33ae0f75 100644
--- a/packages/core/src/render/export-jsx.ts
+++ b/packages/core/src/render/export-jsx.ts
@@ -322,7 +322,7 @@ function collectSizingProps(
): void {
if (ctx.isGrid) collectGridSizingProps(node, props)
else if (ctx.isFlex) collectFlexSizingProps(node, props)
- else if (node.type === 'TEXT') collectTextSizingProps(node, props)
+ else if (node.type === 'TEXT') collectTextSizingProps(node, graph, props)
else {
if (node.width > 0) props.push(['w', node.width])
if (node.height > 0) props.push(['h', node.height])
@@ -339,10 +339,21 @@ function collectSizingProps(
}
}
-function collectTextSizingProps(node: SceneNode, props: [string, unknown][]): void {
+function collectTextSizingProps(node: SceneNode, graph: SceneGraph, props: [string, unknown][]): void {
const autoResize = node.textAutoResize
- const emitW = autoResize !== 'WIDTH_AND_HEIGHT'
const emitH = autoResize === 'NONE' || autoResize === 'TRUNCATE'
+ // Don't emit fixed w when text stretches to fill parent — the layoutAlignSelf
+ // check below will emit w="fill" instead. Without this guard, w={computedPx}
+ // gets emitted first and blocks the fill detection.
+ const isFillWidth = node.layoutAlignSelf === 'STRETCH' && (() => {
+ const parent = node.parentId ? graph.getNode(node.parentId) : null
+ return parent && parent.layoutMode === 'VERTICAL'
+ })()
+ const isGrowWidth = node.layoutGrow > 0 && (() => {
+ const parent = node.parentId ? graph.getNode(node.parentId) : null
+ return parent && parent.layoutMode === 'HORIZONTAL'
+ })()
+ const emitW = autoResize !== 'WIDTH_AND_HEIGHT' && !isFillWidth && !isGrowWidth
if (emitW && node.width > 0) props.push(['w', node.width])
if (emitH && node.height > 0) props.push(['h', node.height])
}
diff --git a/packages/core/src/tools/describe.ts b/packages/core/src/tools/describe.ts
index e127a2c36..6ba2ef3eb 100644
--- a/packages/core/src/tools/describe.ts
+++ b/packages/core/src/tools/describe.ts
@@ -247,6 +247,14 @@ function detectLayoutIssues(node: SceneNode, graph: SceneGraph, issues: Describe
}
if (isAutoLayout) {
+ // wrap without rowGap — wrapped rows stick together
+ if (node.layoutWrap === 'WRAP' && node.counterAxisSpacing <= 0 && children.length > 1) {
+ issues.push({
+ message: `"${node.name}" uses wrap but has no rowGap — wrapped rows will stick together`,
+ suggestion: 'Add rowGap={8} or similar spacing'
+ })
+ }
+
const primarySizing = node.primaryAxisSizing
const primaryDim = isRow ? node.width : node.height
const pad = isRow
diff --git a/src/ai/system-prompt.md b/src/ai/system-prompt.md
index f94730f29..be54887da 100644
--- a/src/ai/system-prompt.md
+++ b/src/ai/system-prompt.md
@@ -16,7 +16,7 @@ These are ALL available props. Nothing else exists — no lineHeight, no letterS
**Sizing:** w={N}, h={N} (fixed px), w="hug"/h="hug" (shrink-to-fit, default), w="fill"/h="fill" (stretch, requires flex parent), grow={N} (flex-grow, requires flex parent with fixed size on that axis), minW={N}, maxW={N}.
-**Layout:** flex="row"|"col" enables auto-layout. gap={N}, wrap, rowGap={N}. justify="start"|"end"|"center"|"between"|"evenly". items="start"|"end"|"center"|"stretch". Padding: p={N}, px={N}, py={N}, pt/pr/pb/pl={N}. Grid: grid, columns="1fr 1fr", rows="1fr", columnGap={N}, rowGap={N}, colStart={N}, rowStart={N}, colSpan={N}, rowSpan={N}.
+**Layout:** flex="row"|"col" enables auto-layout. gap={N}, wrap, rowGap={N}. justify="start"|"end"|"center"|"between"|"evenly". items="start"|"end"|"center"|"stretch". Padding: p={N}, px={N}, py={N}, pt/pr/pb/pl={N}. Grid: grid, columns="1fr 1fr", rows="1fr", columnGap={N}, rowGap={N}, colStart={N}, rowStart={N}, colSpan={N}, rowSpan={N}. ⚠ When using `wrap`, always set `rowGap={N}` — without it, wrapped rows have zero spacing and stick together.
**Appearance:** bg="#hex", stroke="#hex", strokeWidth={N}, rounded={N}, roundedTL/TR/BL/BR={N}, cornerSmoothing={0-1}, opacity={0-1}, rotate={deg}, blendMode="multiply"|"screen"|etc, overflow="hidden", shadow="offX offY blur #color", blur={N}.
diff --git a/tests/engine/render.test.ts b/tests/engine/render.test.ts
index 19491bec4..409b627b4 100644
--- a/tests/engine/render.test.ts
+++ b/tests/engine/render.test.ts
@@ -741,4 +741,36 @@ describe('text props round-trip', () => {
expect(jsx).not.toContain('maxLines')
expect(jsx).not.toContain('truncate')
})
+
+ it('text w="fill" in flex="col" exports as w="fill" not w={computed}', async () => {
+ const g = createGraph()
+ const result = await renderJSX(g, `
+ <Frame name="Card" flex="col" w={300} p={20}>
+ <Text name="Title" size={22} weight="bold" color="#111" w="fill">Hello World</Text>
+ </Frame>
+ `)
+ const card = g.getNode(result.id)!
+ const title = g.getNode(card.childIds[0]!)!
+ expect(title.layoutAlignSelf).toBe('STRETCH')
+ expect(title.textAutoResize).toBe('HEIGHT')
+ const jsx = sceneNodeToJSX(title.id, g)
+ expect(jsx).toContain('w="fill"')
+ expect(jsx).not.toMatch(/w=\{/)
+ })
+
+ it('text grow={1} in flex="row" exports as grow not w={computed}', async () => {
+ const g = createGraph()
+ const result = await renderJSX(g, `
+ <Frame name="Row" flex="row" w={300}>
+ <Text name="Label" color="#999" w={60}>Label</Text>
+ <Text name="Value" color="#111" w="fill">Some value text</Text>
+ </Frame>
+ `)
+ const row = g.getNode(result.id)!
+ const value = g.getNode(row.childIds[1]!)!
+ expect(value.layoutGrow).toBe(1)
+ const jsx = sceneNodeToJSX(value.id, g)
+ expect(jsx).toContain('grow={1}')
+ expect(jsx).not.toMatch(/\bw=\{\d+\}/)
+ })
})