From 5ca94db5d2856fa016fcd8f29458571e6defdd4e Mon Sep 17 00:00:00 2001 From: Himself65 Date: Fri, 14 Apr 2023 00:24:44 -0500 Subject: [PATCH] fix: effect deps (#1940) --- .eslintignore | 1 + .eslintrc.js | 1 + package.json | 1 + .../src/components/block-suite-editor/index.tsx | 2 +- .../src/components/share-menu/SharePage.tsx | 4 ++-- .../share-menu/disable-public-link/index.tsx | 2 +- .../component/src/ui/tree-view/TreeNode.tsx | 2 +- .../component/src/ui/tree-view/TreeView.tsx | 2 +- .../src/use-blocksuite-workspace-avatar-url.ts | 2 +- .../use-blocksuite-workspace-page-is-public.ts | 17 ++++++++++------- yarn.lock | 3 ++- 11 files changed, 22 insertions(+), 15 deletions(-) diff --git a/.eslintignore b/.eslintignore index 2d572ffdc6..b86c8d9e9c 100644 --- a/.eslintignore +++ b/.eslintignore @@ -4,3 +4,4 @@ dist out storybook-static affine-out +_next diff --git a/.eslintrc.js b/.eslintrc.js index b8d843a785..a7b7fc063b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -10,6 +10,7 @@ module.exports = { }, extends: [ 'eslint:recommended', + 'plugin:react-hooks/recommended', 'plugin:react/recommended', 'plugin:react/jsx-runtime', 'plugin:@typescript-eslint/recommended', diff --git a/package.json b/package.json index d8a28349ab..edf6cc04dc 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "eslint-plugin-import": "^2.27.5", "eslint-plugin-prettier": "^4.2.1", "eslint-plugin-react": "^7.32.2", + "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-simple-import-sort": "^10.0.0", "eslint-plugin-unused-imports": "^2.0.0", "fake-indexeddb": "4.0.1", diff --git a/packages/component/src/components/block-suite-editor/index.tsx b/packages/component/src/components/block-suite-editor/index.tsx index 3725f46805..d531b9eabf 100644 --- a/packages/component/src/components/block-suite-editor/index.tsx +++ b/packages/component/src/components/block-suite-editor/index.tsx @@ -50,7 +50,7 @@ const BlockSuiteEditorImpl = (props: EditorProps): ReactElement => { } props.onLoad?.(page, editor); } - }, [props.page, props.onInit, props.onLoad]); + }, [props.page, props.onInit, props.onLoad, editor, props, page]); const ref = useRef(null); diff --git a/packages/component/src/components/share-menu/SharePage.tsx b/packages/component/src/components/share-menu/SharePage.tsx index 53ac49d443..8bf7cd31ef 100644 --- a/packages/component/src/components/share-menu/SharePage.tsx +++ b/packages/component/src/components/share-menu/SharePage.tsx @@ -53,10 +53,10 @@ export const AffineSharePage: FC = props => { }, [props.workspace.id, props.currentPage.id]); const onClickCreateLink = useCallback(() => { setIsPublic(true); - }, [isPublic]); + }, [setIsPublic]); const onClickCopyLink = useCallback(() => { navigator.clipboard.writeText(sharingUrl); - }, []); + }, [sharingUrl]); return (
diff --git a/packages/component/src/components/share-menu/disable-public-link/index.tsx b/packages/component/src/components/share-menu/disable-public-link/index.tsx index 58a346c667..567daa110f 100644 --- a/packages/component/src/components/share-menu/disable-public-link/index.tsx +++ b/packages/component/src/components/share-menu/disable-public-link/index.tsx @@ -32,7 +32,7 @@ export const PublicLinkDisableModal = ({ portal: document.body, }); onClose(); - }, []); + }, [onClose, setIsPublic]); return ( diff --git a/packages/component/src/ui/tree-view/TreeNode.tsx b/packages/component/src/ui/tree-view/TreeNode.tsx index 0c945ab165..f68be7bee7 100644 --- a/packages/component/src/ui/tree-view/TreeNode.tsx +++ b/packages/component/src/ui/tree-view/TreeNode.tsx @@ -78,7 +78,7 @@ const TreeNodeItemWithDnd = ({ if (isOver && canDrop) { setCollapsed(node.id, false); } - }, [isOver, canDrop]); + }, [isOver, canDrop, setCollapsed, node.id]); return ( ({ document.removeEventListener('keydown', handleDirectionKeyDown); document.removeEventListener('keydown', handleEnterKeyDown); }; - }, [data, selectedId]); + }, [data, enableKeyboardSelection, onSelect, selectedId]); const setCollapsed: TreeNodeProps['setCollapsed'] = (id, collapsed) => { if (disableCollapse) { diff --git a/packages/hooks/src/use-blocksuite-workspace-avatar-url.ts b/packages/hooks/src/use-blocksuite-workspace-avatar-url.ts index a6361ddf4c..cbc0ea443c 100644 --- a/packages/hooks/src/use-blocksuite-workspace-avatar-url.ts +++ b/packages/hooks/src/use-blocksuite-workspace-avatar-url.ts @@ -43,6 +43,6 @@ export function useBlockSuiteWorkspaceAvatarUrl( dispose.dispose(); }; } - }, []); + }, [blockSuiteWorkspace]); return [avatar ?? null, setAvatar] as const; } diff --git a/packages/hooks/src/use-blocksuite-workspace-page-is-public.ts b/packages/hooks/src/use-blocksuite-workspace-page-is-public.ts index d9de10b9f9..7200e0e9e9 100644 --- a/packages/hooks/src/use-blocksuite-workspace-page-is-public.ts +++ b/packages/hooks/src/use-blocksuite-workspace-page-is-public.ts @@ -13,12 +13,15 @@ export function useBlockSuiteWorkspacePageIsPublic(page: Page) { page.workspace.meta.pageMetasUpdated.on(() => { set(page.meta.isPublic ?? false); }); - }, []); - const setIsPublic = useCallback((isPublic: boolean) => { - set(isPublic); - page.workspace.setPageMeta(page.id, { - isPublic, - }); - }, []); + }, [page]); + const setIsPublic = useCallback( + (isPublic: boolean) => { + set(isPublic); + page.workspace.setPageMeta(page.id, { + isPublic, + }); + }, + [page.id, page.workspace] + ); return [isPublic, setIsPublic] as const; } diff --git a/yarn.lock b/yarn.lock index 5d7a3ed815..b2a043ca6d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7426,6 +7426,7 @@ __metadata: eslint-plugin-import: ^2.27.5 eslint-plugin-prettier: ^4.2.1 eslint-plugin-react: ^7.32.2 + eslint-plugin-react-hooks: ^4.6.0 eslint-plugin-simple-import-sort: ^10.0.0 eslint-plugin-unused-imports: ^2.0.0 fake-indexeddb: 4.0.1 @@ -10618,7 +10619,7 @@ __metadata: languageName: node linkType: hard -"eslint-plugin-react-hooks@npm:^4.5.0": +"eslint-plugin-react-hooks@npm:^4.5.0, eslint-plugin-react-hooks@npm:^4.6.0": version: 4.6.0 resolution: "eslint-plugin-react-hooks@npm:4.6.0" peerDependencies: