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.

Fix atoms leak (#1312)

Ivan Starkov13db9872370c
diff --git a/apps/builder/app/canvas/canvas.tsx b/apps/builder/app/canvas/canvas.tsx
index 19bc4bbcbf..59cba8c878 100644
--- a/apps/builder/app/canvas/canvas.tsx
+++ b/apps/builder/app/canvas/canvas.tsx
@@ -25,6 +25,7 @@ import {
assetsStore,
pagesStore,
useRootInstance,
+ instancesStore,
useSubscribeScrollState,
useIsPreviewMode,
selectedPageStore,
@@ -55,6 +56,14 @@ const temporaryRootInstance: Instance = {
const useElementsTree = (getComponent: GetComponent) => {
const [rootInstance] = useRootInstance();
+ // @todo remove after https://github.com/webstudio-is/webstudio-builder/issues/1313 now its needed to be sure that no leaks exists
+ // eslint-disable-next-line no-console
+ console.log({
+ assetsStore: assetsStore.get().size,
+ pagesStore: pagesStore.get()?.pages.length ?? 0,
+ instancesStore: instancesStore.get().size,
+ });
+
const pagesMapStore = useMemo(
() =>
computed(pagesStore, (pages): Map<string, Page> => {
diff --git a/apps/builder/app/shared/hook-utils/use-sync-initialize-once.ts b/apps/builder/app/shared/hook-utils/use-sync-initialize-once.ts
index a625172842..fb374ce621 100644
--- a/apps/builder/app/shared/hook-utils/use-sync-initialize-once.ts
+++ b/apps/builder/app/shared/hook-utils/use-sync-initialize-once.ts
@@ -1,16 +1,17 @@
-import { useRef } from "react";
+import { useEffect, useRef } from "react";
// This hook allows to
// 1. run a function only once on the client
-// 2. run it server-side
-// 3. run the function synchronously in both
-// Can't use effect for that (async).
// Can't use useState initializer because it can be called twice in strict mode and also isn't designed for this.
export const useSyncInitializeOnce = (fn: () => void) => {
const ref = useRef(false);
- if (ref.current) {
- return;
- }
- ref.current = true;
- fn();
+
+ useEffect(() => {
+ if (ref.current) {
+ return;
+ }
+ ref.current = true;
+
+ fn();
+ }, [fn]);
};