AI-native design editor. Open-source Figma alternative.
fix(canvas): render stroked container shadows from bounds
Danila Poyarkova49f626e3ec4
diff --git a/packages/core/src/canvas/scene.ts b/packages/core/src/canvas/scene.tsindex 29c214675..77d13e87f 100644--- a/packages/core/src/canvas/scene.ts+++ b/packages/core/src/canvas/scene.ts@@ -297,13 +297,9 @@ export function renderShape(}}-/**- * When a container has no visible fills, Figma renders drop shadows- * using the shape of its children rather than its own rectangle.- * Returns the child to use for shadow shape, or null to use the node itself.- */function getShadowShapeChild(node: SceneNode, graph: SceneGraph): SceneNode | null {if (node.fills.some((f) => f.visible)) return null+ if (node.strokes.some((stroke) => stroke.visible)) return nullif (node.childIds.length === 0) return nullconst child = graph.getNode(node.childIds[0])if (!child?.visible) return nulldiff --git a/packages/core/src/canvas/shadows.ts b/packages/core/src/canvas/shadows.tsindex 572b3ecc5..32b882b45 100644--- a/packages/core/src/canvas/shadows.ts+++ b/packages/core/src/canvas/shadows.ts@@ -135,7 +135,7 @@ function drawShapeDropShadow(if (!shadowShapeChild) {if (hasVisibleFill) {geometryShadow = r.getFillGeometry(node)- } else if (node.strokeGeometry.length > 0) {+ } else if (node.childIds.length === 0 && node.strokeGeometry.length > 0) {geometryShadow = r.getStrokeGeometry(node)}}diff --git a/tests/engine/render/canvas/effects/edge-cases.test.ts b/tests/engine/render/canvas/effects/edge-cases.test.tsindex 11b997a8f..a6ae81584 100644--- a/tests/engine/render/canvas/effects/edge-cases.test.ts+++ b/tests/engine/render/canvas/effects/edge-cases.test.ts@@ -27,7 +27,8 @@ describe('Edge cases and bug fixes', () => {}],strokes: [{ visible: true, weight: 2, opacity: 1 }],- strokeGeometry: [{} as Path]+ strokeGeometry: [{} as Path],+ childIds: []}r.getStrokeGeometry = mock(() => [{} as Path])@@ -37,6 +38,37 @@ describe('Edge cases and bug fixes', () => {expect(canvas.drawPath).toHaveBeenCalled()})+ test('drop shadow on stroked containers uses the container bounds', () => {+ const r = createMockRenderer()+ const canvas = createMockCanvas()+ const node: Partial<SceneNode> = {+ type: 'FRAME',+ width: 224,+ height: 424,+ fills: [],+ effects: [+ {+ type: 'DROP_SHADOW',+ visible: true,+ color: { r: 0, g: 0, b: 0, a: 1 },+ offset: { x: 0, y: 2 },+ radius: 4,+ spread: 0,+ showShadowBehindNode: false+ }+ ],+ strokes: [{ visible: true, weight: 1, opacity: 1 }],+ strokeGeometry: [{} as Path],+ childIds: ['header']+ }+ r.getStrokeGeometry = mock(() => [{} as Path])++ renderEffects(r, canvas as Canvas, node as SceneNode, new Float32Array(4), true, 'behind')++ expect(r.getStrokeGeometry).not.toHaveBeenCalled()+ expect(canvas.drawRRect).toHaveBeenCalled()+ })+test('drop shadow from child applies child transforms (geometric parity)', () => {const r = createMockRenderer()const canvas = createMockCanvas()@@ -333,7 +365,8 @@ describe('Edge cases and bug fixes', () => {spread: 0}],- strokeGeometry: []+ strokeGeometry: [],+ childIds: []}expect(() =>diff --git a/tests/engine/render/canvas/silhouette-autopsy.test.ts b/tests/engine/render/canvas/silhouette-autopsy.test.tsindex 30efb8d03..c8c0de522 100644--- a/tests/engine/render/canvas/silhouette-autopsy.test.ts+++ b/tests/engine/render/canvas/silhouette-autopsy.test.ts@@ -475,42 +475,14 @@ describe('Doc 01/03 — Runtime Behavior Verification', () => {expect(effectTypes).toContain('INNER_SHADOW')})- test('C-RT04: getShadowShapeChild returns null when node has visible fills', () => {- // This function is private in scene.ts, so we test indirectly- // by creating a node with fills and checking that its shadow- // uses its own rect, not a child's shape- const parentWithFill = graph.createNode('FRAME', pageId, {- x: 0,- y: 0,- width: 100,- height: 100,- fills: [{ type: 'SOLID', color: { r: 1, g: 0, b: 0, a: 0.5 }, visible: true, opacity: 1 }],- effects: [- {- type: 'DROP_SHADOW',- visible: true,- color: { r: 0, g: 0, b: 0, a: 1 },- offset: { x: 5, y: 5 },- radius: 10,- spread: 0- }- ]- })-- graph.createNode('RECTANGLE', parentWithFill.id, {- x: 25,- y: 25,- width: 50,- height: 50,- fills: [{ type: 'SOLID', color: { r: 0, g: 0, b: 1, a: 1 }, visible: true, opacity: 1 }]- })-- // renderEffects should use the parent, not the child- // We verify this by checking that the canvas translation matches- // the node's own coordinates (shadowShapeChild would be null)- expect(parentWithFill.fills.some((f) => f.visible)).toBe(true)- // renderShapeUncached passes getShadowShapeChild result to renderEffects- // which returns null when fills are visible → confirms claim+ test('C-RT04: getShadowShapeChild returns null when node has visible fills or strokes', () => {+ const src = readSource(scenePath)+ const getShadowShapeChildFn = src.match(+ /function getShadowShapeChild[\s\S]*?(?=\nfunction |\nexport )/+ )+ const body = expectDefined(getShadowShapeChildFn, 'getShadowShapeChildFn')[0]+ expect(body).toContain('node.fills.some((f) => f.visible)')+ expect(body).toContain('node.strokes.some((stroke) => stroke.visible)')})test('C-RT05: GAP-01 fixed — ColorFilter MakeBlend is captured and .delete()d', () => {