Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

memoized allUserProps, change to object structure

Oleg Isonen93db0b7a7dbb
diff --git a/app/canvas/canvas.tsx b/app/canvas/canvas.tsx
index b054b10812..52218cc5a6 100644
--- a/app/canvas/canvas.tsx
+++ b/app/canvas/canvas.tsx
@@ -84,8 +84,7 @@ export const Canvas = ({ data }: { data: Data }): JSX.Element => {
useActiveElementTracking({ rootInstance });
useShortcuts({ rootInstance });
- // @todo no need to run any of this hooks in preview mode, need to find a better way to switch to preview,
- // probably in the parent component and maybe even fetch the fresh data
+ // @todo no need to run any of this hooks in preview mode, need to find a better way to switch to preview
const isPreviewMode = useIsPreviewMode();
const elements = useElementsTree(
@@ -94,12 +93,14 @@ export const Canvas = ({ data }: { data: Data }): JSX.Element => {
setRootInstance
);
+ const props = useMemo(() => Object.values(allUserProps), [allUserProps]);
+
if (isPreviewMode) {
return (
<CanvasRoot
data={{
tree: { id: data.tree.id, root: rootInstance },
- props: [...allUserProps.values()],
+ props,
}}
/>
);
diff --git a/app/canvas/hooks/publish.ts b/app/canvas/hooks/publish.ts
index 8ca8328cd9..ec887d8bff 100644
--- a/app/canvas/hooks/publish.ts
+++ b/app/canvas/hooks/publish.ts
@@ -22,7 +22,7 @@ export const usePublishSelectedInstance = ({
// Unselects the instance by `undefined`
let payload;
if (instance !== undefined) {
- let props = allUserProps.get(instance.id);
+ let props = allUserProps[instance.id];
if (props === undefined) {
props = {
id: ObjectId().toString(),
diff --git a/app/designer/sync/use-sync.ts b/app/designer/sync/use-sync.ts
index 7016ca9330..100906a4c6 100644
--- a/app/designer/sync/use-sync.ts
+++ b/app/designer/sync/use-sync.ts
@@ -66,7 +66,7 @@ export const useSync = ({
enqueue(() =>
fetch(`/rest/props/update`, {
method: "post",
- body: JSON.stringify({ ...update, treeId: project.devTreeId }),
+ body: JSON.stringify(update),
})
);
});