From 2570871bde7528db0f4c7f659db6b2587e900688 Mon Sep 17 00:00:00 2001 From: svinod Date: Wed, 6 Dec 2023 17:18:20 +0100 Subject: [PATCH 1/2] fix: refresh model for dynamic path --- src/core/EditableComponent.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/EditableComponent.tsx b/src/core/EditableComponent.tsx index 56507c99..c8cbbacc 100644 --- a/src/core/EditableComponent.tsx +++ b/src/core/EditableComponent.tsx @@ -54,6 +54,10 @@ export const EditableComponent = (editableProps: EditableComponentProps): JSX.El const path = cqPath || Utils.getCQPath({ cqPath, pagePath, itemPath }); const [model, setModel] = React.useState(() => userModel || {}); + React.useEffect(() => { + setModel(userModel || {}); + }, [path, userModel]); + React.useEffect(() => { const renderContent = () => updateModel({ path, forceReload, setModel, isInEditor, pagePath }); !Object.keys(model)?.length && renderContent(); @@ -79,7 +83,6 @@ export const EditableComponent = (editableProps: EditableComponentProps): JSX.El const { appliedCssClassNames = '' } = model; const componentClassName = `${className} ${props.containerProps?.className || ''} ${appliedCssClassNames}`.trim(); - const updatedComponent = addPropsToComponent(children, pagePath ? componentProps : model); return isInEditor || (!props.removeDefaultStyles && componentClassName) ? (
From c101fce2faecb3e4b6606ae66e6439a2c8f0c241 Mon Sep 17 00:00:00 2001 From: svinod Date: Wed, 6 Dec 2023 17:24:59 +0100 Subject: [PATCH 2/2] chore: fix code smell --- src/core/EditableComponent.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/EditableComponent.tsx b/src/core/EditableComponent.tsx index c8cbbacc..4d45fd08 100644 --- a/src/core/EditableComponent.tsx +++ b/src/core/EditableComponent.tsx @@ -55,7 +55,7 @@ export const EditableComponent = (editableProps: EditableComponentProps): JSX.El const [model, setModel] = React.useState(() => userModel || {}); React.useEffect(() => { - setModel(userModel || {}); + setModel(userModel ?? {}); }, [path, userModel]); React.useEffect(() => {