From a88296205be2b02ca09ed6d30fae583e9f63de4a Mon Sep 17 00:00:00 2001 From: Oleg Isonen Date: Thu, 4 Aug 2022 19:43:49 +0200 Subject: [PATCH] use ref to check if the value is set, because of SSR we definitely need to find a better pattern, instead of resetting on every request, we should be creating a new container on every request --- apps/designer/app/canvas/shared/instance.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/designer/app/canvas/shared/instance.ts b/apps/designer/app/canvas/shared/instance.ts index 3ac1ef6323..46c95bfd79 100644 --- a/apps/designer/app/canvas/shared/instance.ts +++ b/apps/designer/app/canvas/shared/instance.ts @@ -1,4 +1,4 @@ -import { useCallback, useEffect, useMemo } from "react"; +import { useCallback, useEffect, useMemo, useRef } from "react"; import ObjectId from "bson-objectid"; import { type InstanceProps, @@ -38,8 +38,10 @@ import { import { useMeasure } from "~/shared/dom-hooks"; export const usePopulateRootInstance = (tree: Tree) => { + const ref = useRef(false); // It is only set once when the canvas is first loaded. - if (rootInstanceContainer.value === undefined) { + if (ref.current === false) { + ref.current = true; rootInstanceContainer.value = tree.root; } };