From d73bdc581d32a8047dae543cee49c69913772271 Mon Sep 17 00:00:00 2001 From: Balazs Bajorics <2226774+balazsbajorics@users.noreply.github.com> Date: Mon, 17 Jun 2024 22:34:46 +0200 Subject: [PATCH] REPLACE_JSX_ELEMENT to preserve UID of element-to-be-replaced --- editor/src/components/editor/actions/actions.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/editor/src/components/editor/actions/actions.tsx b/editor/src/components/editor/actions/actions.tsx index 9863df541927..14c2163a97fb 100644 --- a/editor/src/components/editor/actions/actions.tsx +++ b/editor/src/components/editor/actions/actions.tsx @@ -442,6 +442,7 @@ import { fixUtopiaElement, generateConsistentUID, getUtopiaID, + setUtopiaID, } from '../../../core/shared/uid-utils' import { DefaultPostCSSConfig, @@ -2358,8 +2359,6 @@ export const UPDATE_FNS = { } }, REPLACE_JSX_ELEMENT: (action: ReplaceJSXElement, editor: EditorModel): EditorModel => { - let newSelectedViews: ElementPath[] = [] - const withNewElement = modifyUnderlyingParseSuccessOnly( action.target, editor, @@ -2382,7 +2381,15 @@ export const UPDATE_FNS = { ) const fixedElement = (() => { - const renamedJsxElement = renameJsxElementChild(action.jsxElement, duplicateNameMapping) + const elemenWithOriginalUid = setUtopiaID( + action.jsxElement, + getUtopiaID(originalElement), + ) as JSXElement + + const renamedJsxElement = renameJsxElementChild( + elemenWithOriginalUid, + duplicateNameMapping, + ) if ( !isReplaceKeepChildrenAndStyleTarget(action.behaviour) || originalElement.type !== 'JSX_ELEMENT' @@ -2435,7 +2442,6 @@ export const UPDATE_FNS = { return { ...withNewElement, leftMenu: { visible: editor.leftMenu.visible, selectedTab: LeftMenuTab.Navigator }, - selectedViews: newSelectedViews, } }, REPLACE_MAPPED_ELEMENT: (action: ReplaceMappedElement, editor: EditorModel): EditorModel => {