From abb1a3868b284ab24fd35bfa1640e7aa6279f756 Mon Sep 17 00:00:00 2001 From: fantasticit Date: Mon, 2 May 2022 17:46:46 +0800 Subject: [PATCH] fix: memo editor --- .../src/components/document/editor/editor.tsx | 15 ++++++++++++++- .../src/components/document/editor/index.tsx | 1 - 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/client/src/components/document/editor/editor.tsx b/packages/client/src/components/document/editor/editor.tsx index 1ba184a0..65b480f3 100644 --- a/packages/client/src/components/document/editor/editor.tsx +++ b/packages/client/src/components/document/editor/editor.tsx @@ -1,6 +1,7 @@ import Router from 'next/router'; import React, { useMemo, useEffect, useState, useRef } from 'react'; import cls from 'classnames'; +import deepEqual from 'deep-equal'; import { BackTop, Toast, Spin, Typography } from '@douyinfe/semi-ui'; import { ILoginUser, IAuthority } from '@think/domains'; import { SecureDocumentIllustration } from 'illustrations/secure-document'; @@ -40,7 +41,7 @@ interface IProps { const { Text } = Typography; -export const Editor: React.FC = ({ user: currentUser, documentId, authority, className, style }) => { +export const _Editor: React.FC = ({ user: currentUser, documentId, authority, className, style }) => { const $hasShowUserSettingModal = useRef(false); const { users, addUser, updateUser } = useCollaborationDocument(documentId); const [status, setStatus] = useState('connecting'); @@ -251,3 +252,15 @@ export const Editor: React.FC = ({ user: currentUser, documentId, author /> ); }; + +export const Editor = React.memo(_Editor, (prevProps, nextProps) => { + if (deepEqual(prevProps, nextProps)) return true; + Toast.info({ + content: '信息已更新,我们将为您重新加载页面!', + duration: 3, + onClose() { + Router.reload(); + }, + }); + return false; +}); diff --git a/packages/client/src/components/document/editor/index.tsx b/packages/client/src/components/document/editor/index.tsx index 7191b902..db806e21 100644 --- a/packages/client/src/components/document/editor/index.tsx +++ b/packages/client/src/components/document/editor/index.tsx @@ -117,7 +117,6 @@ export const DocumentEditor: React.FC = ({ documentId }) => { <>