diff --git a/packages/fig/src/instance-overrides/component-props/apply.ts b/packages/fig/src/instance-overrides/component-props/apply.ts index 4c6540a25..265e36fde 100644 --- a/packages/fig/src/instance-overrides/component-props/apply.ts +++ b/packages/fig/src/instance-overrides/component-props/apply.ts @@ -62,7 +62,10 @@ function applySwapProp( const swapId = propTextCharacters(val) ?? (val.guidValue ? guidToString(val.guidValue) : undefined) const newCompId = swapId ? ctx.guidToNodeId.get(swapId) : undefined - if (!newCompId) return + const currentCompId = ctx.graph.getNode(childId)?.componentId + if (currentCompId && getComponentRoot(ctx, currentCompId) === getComponentRoot(ctx, newCompId)) { + return + } applyPatchAndMark( ctx, childId, diff --git a/packages/fig/src/instance-overrides/component-props/values.ts b/packages/fig/src/instance-overrides/component-props/values.ts index 4b64513b5..0799b4f0d 100644 --- a/packages/fig/src/instance-overrides/component-props/values.ts +++ b/packages/fig/src/instance-overrides/component-props/values.ts @@ -17,7 +17,8 @@ export function propTextCharacters(value: ComponentPropValue): string | undefine return value.textValue?.characters ?? value.textDataValue?.characters } -function isEmptyPropValue(v: ComponentPropValue): boolean { +function isEmptyPropValue(v: ComponentPropValue | undefined): boolean { + if (!v) return true return ( v.boolValue === undefined && v.textValue === undefined && @@ -31,8 +32,9 @@ function resolveAssignmentValue( assignment: ComponentPropAssignment, key: string, resolveDefaults: boolean -): ComponentPropValue { - if (!isEmptyPropValue(assignment.value)) return assignment.value +): ComponentPropValue | undefined { + const value = assignment.value + if (value && !isEmptyPropValue(value)) return value const variableValue = assignment.varValue?.value if (variableValue?.symbolIdValue?.guid) return { guidValue: variableValue.symbolIdValue.guid } @@ -53,7 +55,8 @@ export function assignmentsToValueMap( for (const assignment of assignments) { if (!assignment.defID) continue const key = guidToString(assignment.defID) - valueByDef.set(key, resolveAssignmentValue(ctx, assignment, key, resolveDefaults)) + const value = resolveAssignmentValue(ctx, assignment, key, resolveDefaults) + if (value) valueByDef.set(key, value) } return valueByDef } diff --git a/packages/fig/src/instance-overrides/types.ts b/packages/fig/src/instance-overrides/types.ts index 1a62dd7aa..1bdcf06d3 100644 --- a/packages/fig/src/instance-overrides/types.ts +++ b/packages/fig/src/instance-overrides/types.ts @@ -38,7 +38,7 @@ export type ComponentPropValue = { export interface ComponentPropAssignment { defID?: GUID - value: ComponentPropValue + value?: ComponentPropValue varValue?: { value?: { boolValue?: boolean