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.

Remove scroll state from builder as not useful (#1315)

Bogdan Chadkin1163d2c8634c
diff --git a/apps/builder/app/builder/features/workspace/canvas-tools/canvas-tools.tsx b/apps/builder/app/builder/features/workspace/canvas-tools/canvas-tools.tsx
index d598566983..f5620bd7b4 100644
--- a/apps/builder/app/builder/features/workspace/canvas-tools/canvas-tools.tsx
+++ b/apps/builder/app/builder/features/workspace/canvas-tools/canvas-tools.tsx
@@ -4,8 +4,6 @@ import { Box } from "@webstudio-is/design-system";
import { PlacementIndicator } from "@webstudio-is/design-system";
import {
useIsPreviewMode,
- useIsScrolling,
- useSubscribeScrollState,
useDragAndDropState,
useSubscribeDragAndDropState,
instancesStore,
@@ -34,12 +32,10 @@ type CanvasToolsProps = {
export const CanvasTools = ({ publish }: CanvasToolsProps) => {
// @todo try to setup cross-frame atoms to vaoid this
useSubscribeInstanceRect();
- useSubscribeScrollState();
useSubscribeDragAndDropState();
useSubscribeSwitchPage();
const [isPreviewMode] = useIsPreviewMode();
- const [isScrolling] = useIsScrolling();
const [dragAndDropState] = useDragAndDropState();
const instances = useStore(instancesStore);
@@ -65,7 +61,7 @@ export const CanvasTools = ({ publish }: CanvasToolsProps) => {
) : null;
}
- if (isPreviewMode || isScrolling) {
+ if (isPreviewMode) {
return null;
}
return (
diff --git a/apps/builder/app/canvas/canvas.tsx b/apps/builder/app/canvas/canvas.tsx
index 59cba8c878..3383d70c06 100644
--- a/apps/builder/app/canvas/canvas.tsx
+++ b/apps/builder/app/canvas/canvas.tsx
@@ -26,11 +26,9 @@ import {
pagesStore,
useRootInstance,
instancesStore,
- useSubscribeScrollState,
useIsPreviewMode,
selectedPageStore,
} from "~/shared/nano-states";
-import { usePublishScrollState } from "./shared/use-publish-scroll-state";
import { useDragAndDrop } from "./shared/use-drag-drop";
import { useSubscribeBuilderReady } from "./shared/use-builder-ready";
import { useCopyPaste } from "~/shared/copy-paste";
@@ -94,8 +92,6 @@ const useElementsTree = (getComponent: GetComponent) => {
const DesignMode = () => {
useManageDesignModeStyles();
- usePublishScrollState();
- useSubscribeScrollState();
useDragAndDrop();
// We need to initialize this in both canvas and builder,
// because the events will fire in either one, depending on where the focus is
diff --git a/apps/builder/app/canvas/features/text-editor/toolbar-connector.tsx b/apps/builder/app/canvas/features/text-editor/toolbar-connector.tsx
index e99f4dc2ad..73459ffa48 100644
--- a/apps/builder/app/canvas/features/text-editor/toolbar-connector.tsx
+++ b/apps/builder/app/canvas/features/text-editor/toolbar-connector.tsx
@@ -15,7 +15,7 @@ import { LinkNode, TOGGLE_LINK_COMMAND } from "@lexical/link";
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
import { useSubscribe } from "~/shared/pubsub";
import { textToolbarStore } from "~/shared/nano-states/canvas";
-import { subscribeScrollState } from "~/shared/dom-hooks";
+import { subscribeScrollState } from "~/canvas/shared/scroll-state";
const spanTriggerName = "--style-node-trigger";
diff --git a/apps/builder/app/canvas/features/webstudio-component/selected-instance-connector.ts b/apps/builder/app/canvas/features/webstudio-component/selected-instance-connector.ts
index 8314c04dfc..dd5dc60560 100644
--- a/apps/builder/app/canvas/features/webstudio-component/selected-instance-connector.ts
+++ b/apps/builder/app/canvas/features/webstudio-component/selected-instance-connector.ts
@@ -3,15 +3,13 @@ import { useStore } from "@nanostores/react";
import type { Instance, Prop, StyleDecl } from "@webstudio-is/project-build";
import { getBrowserStyle } from "@webstudio-is/react-sdk";
import { publish, subscribe } from "~/shared/pubsub";
-import {
- subscribeScrollState,
- subscribeWindowResize,
-} from "~/shared/dom-hooks";
+import { subscribeWindowResize } from "~/shared/dom-hooks";
import {
rootInstanceContainer,
selectedInstanceBrowserStyleStore,
} from "~/shared/nano-states";
import { getAllElementsBoundingBox } from "~/shared/dom-utils";
+import { subscribeScrollState } from "~/canvas/shared/scroll-state";
declare module "~/shared/pubsub" {
export interface PubsubMap {
diff --git a/apps/builder/app/canvas/instance-hovering.ts b/apps/builder/app/canvas/instance-hovering.ts
index a3735d786b..b935ddf651 100644
--- a/apps/builder/app/canvas/instance-hovering.ts
+++ b/apps/builder/app/canvas/instance-hovering.ts
@@ -5,12 +5,12 @@ import {
hoveredInstanceOutlineStore,
instancesStore,
} from "~/shared/nano-states";
-import { subscribeScrollState } from "~/shared/dom-hooks";
import {
getAllElementsBoundingBox,
getElementByInstanceSelector,
getInstanceSelectorFromElement,
} from "~/shared/dom-utils";
+import { subscribeScrollState } from "./shared/scroll-state";
type TimeoutId = undefined | ReturnType<typeof setTimeout>;
diff --git a/apps/builder/app/shared/dom-hooks/use-scroll-state.ts b/apps/builder/app/canvas/shared/scroll-state.ts
similarity index 79%
rename from apps/builder/app/shared/dom-hooks/use-scroll-state.ts
rename to apps/builder/app/canvas/shared/scroll-state.ts
index 395f887d4d..14297660ae 100644
--- a/apps/builder/app/shared/dom-hooks/use-scroll-state.ts
+++ b/apps/builder/app/canvas/shared/scroll-state.ts
@@ -1,6 +1,4 @@
-import { useEffect } from "react";
import mitt from "mitt";
-import noop from "lodash.noop";
// Using a JS emitter to avoid overhead with subscribing scroll event directly on the DOM by many listeners
const emitter = mitt();
@@ -41,6 +39,13 @@ type UseScrollState = {
onScrollEnd?: () => void;
};
+// eslint-disable-next-line @typescript-eslint/no-empty-function
+const noop = () => {};
+
+/**
+ * Scroll state abstraction that can handle a lot of subscribers well.
+ * Potentially could add rate limiting and actual scroll top/left values.
+ */
export const subscribeScrollState = ({
onScroll = noop,
onScrollStart = noop,
@@ -56,22 +61,3 @@ export const subscribeScrollState = ({
emitter.off("scrollEnd", onScrollEnd);
};
};
-
-/**
- * Scroll state abstraction that can handle a lot of subscribers well.
- * Potentially could add rate limiting and actual scroll top/left values.
- */
-export const useScrollState = ({
- onScroll,
- onScrollStart,
- onScrollEnd,
-}: UseScrollState) => {
- useEffect(() => {
- const unsubscribe = subscribeScrollState({
- onScrollStart,
- onScroll,
- onScrollEnd,
- });
- return unsubscribe;
- }, [onScroll, onScrollEnd, onScrollStart]);
-};
diff --git a/apps/builder/app/canvas/shared/use-publish-scroll-state.ts b/apps/builder/app/canvas/shared/use-publish-scroll-state.ts
deleted file mode 100644
index 330acd8dd1..0000000000
--- a/apps/builder/app/canvas/shared/use-publish-scroll-state.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import { useScrollState } from "~/shared/dom-hooks";
-import { publish } from "~/shared/pubsub";
-
-declare module "~/shared/pubsub" {
- export interface PubsubMap {
- scrollState: boolean;
- }
-}
-
-export const usePublishScrollState = () => {
- useScrollState({
- onScrollStart() {
- publish({ type: "scrollState", payload: true });
- },
- onScrollEnd() {
- publish({
- type: "scrollState",
- payload: false,
- });
- },
- });
-};
diff --git a/apps/builder/app/shared/dom-hooks/index.ts b/apps/builder/app/shared/dom-hooks/index.ts
index 0e0923f601..ac94eeeefa 100644
--- a/apps/builder/app/shared/dom-hooks/index.ts
+++ b/apps/builder/app/shared/dom-hooks/index.ts
@@ -1,2 +1 @@
export * from "./use-window-resize";
-export * from "./use-scroll-state";
diff --git a/apps/builder/app/shared/nano-states/index.ts b/apps/builder/app/shared/nano-states/index.ts
index bf06cc8410..a1a7e5a60b 100644
--- a/apps/builder/app/shared/nano-states/index.ts
+++ b/apps/builder/app/shared/nano-states/index.ts
@@ -1,3 +1,2 @@
export * from "./nano-states";
-export * from "./use-subscribe-scroll-state";
export * from "./use-subscribe-drag-drop-state";
diff --git a/apps/builder/app/shared/nano-states/nano-states.ts b/apps/builder/app/shared/nano-states/nano-states.ts
index b7040770f8..292ec75bc1 100644
--- a/apps/builder/app/shared/nano-states/nano-states.ts
+++ b/apps/builder/app/shared/nano-states/nano-states.ts
@@ -420,9 +420,6 @@ const selectedInstanceOutlineContainer = atom<{
export const useSelectedInstanceOutline = () =>
useValue(selectedInstanceOutlineContainer);
-const isScrollingContainer = atom<boolean>(false);
-export const useIsScrolling = () => useValue(isScrollingContainer);
-
export type DragAndDropState = {
isDragging: boolean;
dropTarget?: ItemDropTarget;
diff --git a/apps/builder/app/shared/nano-states/use-subscribe-scroll-state.ts b/apps/builder/app/shared/nano-states/use-subscribe-scroll-state.ts
deleted file mode 100644
index dd4c1662d2..0000000000
--- a/apps/builder/app/shared/nano-states/use-subscribe-scroll-state.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-import { useSubscribe } from "~/shared/pubsub";
-import { useIsScrolling } from "./nano-states";
-
-export const useSubscribeScrollState = () => {
- const [, setIsScrolling] = useIsScrolling();
- useSubscribe("scrollState", setIsScrolling);
-};
diff --git a/apps/builder/package.json b/apps/builder/package.json
index 4564ad97f6..27989828cd 100644
--- a/apps/builder/package.json
+++ b/apps/builder/package.json
@@ -73,7 +73,6 @@
"lodash.debounce": "^4.0.8",
"lodash.memoize": "^4.1.2",
"lodash.merge": "^4.6.2",
- "lodash.noop": "^3.0.1",
"lodash.snakecase": "^4.1.1",
"match-sorter": "^6.3.1",
"mdast-util-from-markdown": "^1.3.0",
@@ -116,7 +115,6 @@
"@types/lodash.debounce": "^4.0.6",
"@types/lodash.memoize": "^4.1.6",
"@types/lodash.merge": "^4.6.6",
- "@types/lodash.noop": "^3.0.6",
"@types/lodash.snakecase": "^4.1.6",
"@types/react": "^17.0.24",
"@types/react-color": "^3.0.6",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 7a05e6dcea..e5d8a62d70 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -213,9 +213,6 @@ importers:
lodash.merge:
specifier: ^4.6.2
version: 4.6.2
- lodash.noop:
- specifier: ^3.0.1
- version: 3.0.1
lodash.snakecase:
specifier: ^4.1.1
version: 4.1.1
@@ -337,9 +334,6 @@ importers:
'@types/lodash.merge':
specifier: ^4.6.6
version: 4.6.7
- '@types/lodash.noop':
- specifier: ^3.0.6
- version: 3.0.7
'@types/lodash.snakecase':
specifier: ^4.1.6
version: 4.1.7
@@ -8555,12 +8549,6 @@ packages:
'@types/lodash': 4.14.182
dev: true
- resolution: {integrity: sha512-vaQ5DABJ4lDb58EVHnSTyOjkCem+Wj6QF0s8Ybhvt7kFyJCoRmjEajg6vg30jCN8CVZi89uRR5wqQWn724JQHg==}
- dependencies:
- '@types/lodash': 4.14.182
- dev: true
-
resolution: {integrity: sha512-nv9M+JJokFyfZ9QmaWVXZu2DfT40K0GictZaA8SwXczp3oCzMkjp7PtvUBQyvdoG9SnlCpoRXZDIVwQRzJbd9A==}
dependencies:
@@ -15138,10 +15126,6 @@ packages:
resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==}
dev: false
- resolution: {integrity: sha512-TmYdmu/pebrdTIBDK/FDx9Bmfzs9x0sZG6QIJuMDTqEPfeciLcN13ij+cOd0i9vwJfBtbG9UQ+C7MkXgYxrIJg==}
- dev: false
-
resolution: {integrity: sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==}
dev: false