Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPLACE_JSX_ELEMENT to preserve UID of element-to-be-replaced #5976

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions editor/src/components/editor/actions/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ import {
fixUtopiaElement,
generateConsistentUID,
getUtopiaID,
setUtopiaID,
} from '../../../core/shared/uid-utils'
import {
DefaultPostCSSConfig,
Expand Down Expand Up @@ -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,
Expand All @@ -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'
Expand Down Expand Up @@ -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 => {
Expand Down
Loading