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.

lint hooks

Oleg Isonencf806d18a651
diff --git a/.eslintrc.json b/.eslintrc.json
index fc5bce80d2..466b81de7f 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -7,7 +7,8 @@
"extends": [
"eslint:recommended",
"plugin:react/recommended",
- "plugin:@typescript-eslint/recommended"
+ "plugin:@typescript-eslint/recommended",
+ "plugin:react-hooks/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
diff --git a/app/canvas/canvas.tsx b/app/canvas/canvas.tsx
index 5a5c13a37e..08c0deb31b 100644
--- a/app/canvas/canvas.tsx
+++ b/app/canvas/canvas.tsx
@@ -48,7 +48,7 @@ const useElementsTree = (
payload: change,
});
},
- [rootInstance]
+ [rootInstance, setRootInstance]
);
return useMemo(
@@ -58,7 +58,7 @@ const useElementsTree = (
Component,
onChangeChildren,
}),
- [rootInstance]
+ [rootInstance, onChangeChildren, Component]
);
};
diff --git a/app/canvas/hooks/active-element.ts b/app/canvas/hooks/active-element.ts
index bff136233b..d81178445f 100644
--- a/app/canvas/hooks/active-element.ts
+++ b/app/canvas/hooks/active-element.ts
@@ -64,7 +64,7 @@ export const useActiveElementTracking = ({
window.removeEventListener("focus", handleFocus);
window.removeEventListener("click", handleClick);
};
- }, [rootInstance]);
+ }, [rootInstance, setSelectedElement, setSelectedInstance]);
return selectedInstance;
};
diff --git a/app/canvas/hooks/publish.ts b/app/canvas/hooks/publish.ts
index ec887d8bff..f79512faf8 100644
--- a/app/canvas/hooks/publish.ts
+++ b/app/canvas/hooks/publish.ts
@@ -44,7 +44,7 @@ export const usePublishSelectedInstance = ({
type: "selectInstance",
payload,
});
- }, [instance, selectedElement]);
+ }, [instance, selectedElement, allUserProps, treeId]);
};
export const usePublishRootInstance = (instance: Instance) => {
diff --git a/app/canvas/hooks/tree.ts b/app/canvas/hooks/tree.ts
index b0a46aa1b4..d3e7058707 100644
--- a/app/canvas/hooks/tree.ts
+++ b/app/canvas/hooks/tree.ts
@@ -46,7 +46,12 @@ export const useInsertInstance = ({
if (insertedInstance !== undefined) {
setSelectedInstance(insertedInstance);
}
- }, [instanceInsertionSpec, rootInstance]);
+ }, [
+ instanceInsertionSpec,
+ rootInstance,
+ setRootInstance,
+ setSelectedInstance,
+ ]);
};
export const useReparentInstance = ({
@@ -65,7 +70,7 @@ export const useReparentInstance = ({
instanceReparentingSpec
);
setRootInstance(updatedRootInstance);
- }, [instanceReparentingSpec, rootInstance]);
+ }, [instanceReparentingSpec, rootInstance, setRootInstance]);
};
export const useDeleteInstance = ({
diff --git a/app/canvas/wrapper-component/editable/use-content-editable.tsx b/app/canvas/wrapper-component/editable/use-content-editable.tsx
index 8a07c4ff95..8bcd707b11 100644
--- a/app/canvas/wrapper-component/editable/use-content-editable.tsx
+++ b/app/canvas/wrapper-component/editable/use-content-editable.tsx
@@ -1,4 +1,4 @@
-import { useState, useRef, useEffect } from "react";
+import { useState, useRef, useEffect, useCallback } from "react";
import { useHotkeys } from "react-hotkeys-hook";
import useDebounce from "react-use/lib/useDebounce";
import ObjectId from "bson-objectid";
@@ -152,16 +152,19 @@ export const useContentEditable = ({
[contentChanged]
);
- const toggleDisable = (nextIsDisabled: boolean) => {
- if (isContentEditable !== false && isDisabled !== nextIsDisabled) {
- if (nextIsDisabled === false) {
- innerHtmlRef.current = { __html: ref.current?.innerHTML || "" };
- } else {
- innerHtmlRef.current = undefined;
+ const toggleDisable = useCallback(
+ (nextIsDisabled: boolean) => {
+ if (isContentEditable !== false && isDisabled !== nextIsDisabled) {
+ if (nextIsDisabled === false) {
+ innerHtmlRef.current = { __html: ref.current?.innerHTML || "" };
+ } else {
+ innerHtmlRef.current = undefined;
+ }
+ setIsDisabled(nextIsDisabled);
}
- setIsDisabled(nextIsDisabled);
- }
- };
+ },
+ [isContentEditable, isDisabled]
+ );
const editable = useEditable<ContentItem>(ref, handleChangeContent, {
disabled: isDisabled,
@@ -195,7 +198,7 @@ export const useContentEditable = ({
if (selectedInstance?.id !== id) {
toggleDisable(true);
}
- }, [selectedInstance]);
+ }, [selectedInstance, id, toggleDisable]);
const toolbar = useToolbar({
editable: isContentEditable && isDisabled === false ? editable : undefined,
diff --git a/app/canvas/wrapper-component/editable/use-editable.tsx b/app/canvas/wrapper-component/editable/use-editable.tsx
index ffcc1f46fe..838a2bf737 100644
--- a/app/canvas/wrapper-component/editable/use-editable.tsx
+++ b/app/canvas/wrapper-component/editable/use-editable.tsx
@@ -1,4 +1,4 @@
-/* eslint-disable @typescript-eslint/no-non-null-assertion */
+/* eslint-disable @typescript-eslint/no-non-null-assertion, react-hooks/exhaustive-deps, react-hooks/rules-of-hooks */
// Copied from https://github.com/FormidableLabs/use-editable
// @todo create an issue there and if they agree - contribute
// @todo had too many bugs and had to resort to an uncontrolled mode over innerHTML. It totally defeats the idea behind this code
diff --git a/app/canvas/wrapper-component/use-css.tsx b/app/canvas/wrapper-component/use-css.tsx
index bc8576a937..ff98082c8b 100644
--- a/app/canvas/wrapper-component/use-css.tsx
+++ b/app/canvas/wrapper-component/use-css.tsx
@@ -72,5 +72,5 @@ export const useCss = ({ id, component, css }: UseCssProps): string => {
}
return createCss(css)({ css: overrides });
- }, [dragData, selectedInstance, css]);
+ }, [dragData, selectedInstance, css, component, id]);
};
diff --git a/app/canvas/wrapper-component/use-draggable.ts b/app/canvas/wrapper-component/use-draggable.ts
index 66a8b24a49..6393a2def6 100644
--- a/app/canvas/wrapper-component/use-draggable.ts
+++ b/app/canvas/wrapper-component/use-draggable.ts
@@ -62,7 +62,7 @@ export const useDraggable = ({ id, component, isDisabled }: UseDraggable) => {
event.stopPropagation();
}
},
- [isDisabled, id]
+ [isDisabled]
);
return { dragRefCallback, onMouseDownCapture: handleMouseDown };
diff --git a/app/canvas/wrapper-component/wrapper-component.tsx b/app/canvas/wrapper-component/wrapper-component.tsx
index df33192b6f..9ccbb67ec5 100644
--- a/app/canvas/wrapper-component/wrapper-component.tsx
+++ b/app/canvas/wrapper-component/wrapper-component.tsx
@@ -47,11 +47,14 @@ export const WrapperComponentDev = ({
isDisabled: isContentEditableDisabled === false,
});
- const refCallback = useCallback((element) => {
- contentEditableRef.current = element;
- // We can't drag if we are editing text.
- dragRefCallback(element);
- }, []);
+ const refCallback = useCallback(
+ (element) => {
+ contentEditableRef.current = element;
+ // We can't drag if we are editing text.
+ dragRefCallback(element);
+ },
+ [contentEditableRef, dragRefCallback]
+ );
const userProps = useUserProps(id);
diff --git a/app/designer/settings-panel/use-props-logic.ts b/app/designer/settings-panel/use-props-logic.ts
index ce4c6fd410..bda3d8c6c4 100644
--- a/app/designer/settings-panel/use-props-logic.ts
+++ b/app/designer/settings-panel/use-props-logic.ts
@@ -38,11 +38,12 @@ export const usePropsLogic = ({
? initialUserProps
: selectedInstanceData.props.props;
setUserProps(props);
- }, [selectedInstanceData?.props]);
+ }, [selectedInstanceData]);
+ // @todo this may call the last callback after unmount
+ // use useDebounce
+ // eslint-disable-next-line react-hooks/exhaustive-deps
const updateProps = useCallback(
- // @todo this may call the last callback after unmount
- // use useDebounce
debounce((updates: UserPropsUpdates["updates"]) => {
if (selectedInstanceData === undefined) {
return;
diff --git a/app/designer/sidebar-left/custom-drag-layer.tsx b/app/designer/sidebar-left/custom-drag-layer.tsx
index 2379df82dc..f7c82e5747 100644
--- a/app/designer/sidebar-left/custom-drag-layer.tsx
+++ b/app/designer/sidebar-left/custom-drag-layer.tsx
@@ -43,7 +43,7 @@ export const CustomDragLayer = ({ onDrag }: CustomDragLayerProps) => {
currentOffset,
component: itemType,
});
- }, [clientOffset, initialOffset, itemType]);
+ }, [clientOffset, initialOffset, itemType, onDrag]);
if (isDragging === false) return null;
diff --git a/app/designer/sidebar-left/panels/components.tsx b/app/designer/sidebar-left/panels/components.tsx
index 539e7a2b16..ee01abccb7 100644
--- a/app/designer/sidebar-left/panels/components.tsx
+++ b/app/designer/sidebar-left/panels/components.tsx
@@ -42,7 +42,7 @@ const Component = ({
useEffect(() => {
if (lastIsDragging.current !== undefined) onDragChange(isDragging);
lastIsDragging.current = isDragging;
- }, [isDragging]);
+ }, [isDragging, onDragChange]);
return (
<Flex
diff --git a/app/designer/sidebar-left/panels/tree.tsx b/app/designer/sidebar-left/panels/tree.tsx
index b56d805f2a..077782ffb2 100644
--- a/app/designer/sidebar-left/panels/tree.tsx
+++ b/app/designer/sidebar-left/panels/tree.tsx
@@ -70,7 +70,7 @@ const Tree = ({
);
}
return children;
- }, [instance, level, isOpen, selectedInstanceId]);
+ }, [instance, level, isOpen, selectedInstanceId, onSelect, showChildren]);
const { Icon, label } = primitives[instance.component];
diff --git a/app/designer/style-panel/use-style-data.ts b/app/designer/style-panel/use-style-data.ts
index 2fce030ec9..d8c2944c98 100644
--- a/app/designer/style-panel/use-style-data.ts
+++ b/app/designer/style-panel/use-style-data.ts
@@ -31,7 +31,7 @@ export const useStyleData = ({
return;
}
return getInheritedStyle(rootInstance, selectedInstanceData.id);
- }, [currentStyle]);
+ }, [currentStyle, selectedInstanceData, rootInstance]);
useEffect(() => {
setCurrentStyle({
diff --git a/app/designer/topbar/publish.tsx b/app/designer/topbar/publish.tsx
index 2e06402e42..f4e58c9bd3 100644
--- a/app/designer/topbar/publish.tsx
+++ b/app/designer/topbar/publish.tsx
@@ -29,7 +29,7 @@ const Content = ({ project }: PublishProps) => {
return;
}
setUrl(`${location.protocol}//${domain}.${location.host}`);
- }, [project.domain, fetcher.data?.domain]);
+ }, [domain]);
return (
<PopoverContent
diff --git a/package.json b/package.json
index 1af7438b11..21bc1ec73c 100644
--- a/package.json
+++ b/package.json
@@ -7,7 +7,7 @@
"dev": "node -r dotenv/config node_modules/.bin/remix dev",
"postinstall": "remix setup node",
"typecheck": "tsc -b",
- "lint": "eslint . --ext .ts,.tsx",
+ "lint": "eslint . --ext .ts,.tsx --max-warnings 0",
"test": "jest"
},
"dependencies": {
@@ -92,6 +92,7 @@
"esbuild-node-loader": "^0.8.0",
"eslint": "^8.11.0",
"eslint-plugin-react": "^7.29.4",
+ "eslint-plugin-react-hooks": "^4.3.0",
"jest": "^27.5.1",
"typescript": "^4.1.2"
},
diff --git a/yarn.lock b/yarn.lock
index 8352d42c50..eba447a0bb 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3341,6 +3341,11 @@ escodegen@^2.0.0:
optionalDependencies:
source-map "~0.6.1"
+eslint-plugin-react-hooks@^4.3.0:
+ version "4.3.0"
+ resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.3.0.tgz#318dbf312e06fab1c835a4abef00121751ac1172"
+ integrity sha512-XslZy0LnMn+84NEG9jSGR6eGqaZB3133L8xewQo3fQagbQuGt7a63gf+P1NGKZavEYEC3UXaWEAA/AqDkuN6xA==
+
eslint-plugin-react@^7.29.4:
version "7.29.4"
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.29.4.tgz#4717de5227f55f3801a5fd51a16a4fa22b5914d2"