Browse Source

Merge pull request #8526 from weseek/fix/mutation-for-current-page-2

fix: Mutation for current page 2
Yuki Takei 2 years ago
parent
commit
a818930ca3
2 changed files with 7 additions and 4 deletions
  1. 3 3
      apps/app/src/components/PageEditor/PageEditor.tsx
  2. 4 1
      apps/app/src/stores/page.tsx

+ 3 - 3
apps/app/src/components/PageEditor/PageEditor.tsx

@@ -200,9 +200,9 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
   }, [socket, checkIsConflict]);
 
   const save = useCallback(async(opts?: {slackChannels: string, overwriteScopesOfDescendants?: boolean}): Promise<IPageHasId | null> => {
-    if (pageId == null || currentPagePath == null || currentRevisionId == null || grantData == null) {
+    if (pageId == null || currentRevisionId == null || grantData == null) {
       logger.error('Some materials to save are invalid', {
-        pageId, currentPagePath, currentRevisionId, grantData,
+        pageId, currentRevisionId, grantData,
       });
       throw new Error('Some materials to save are invalid');
     }
@@ -242,7 +242,7 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
     }
 
   // eslint-disable-next-line max-len
-  }, [codeMirrorEditor, grantData, pageId, currentPagePath, currentRevisionId, mutateWaitingSaveProcessing, mutateRemotePageId, mutateRemoteRevisionId, mutateRemoteRevisionLastUpdatedAt, mutateRemoteRevisionLastUpdateUser]);
+  }, [codeMirrorEditor, grantData, pageId, currentRevisionId, mutateWaitingSaveProcessing, mutateRemotePageId, mutateRemoteRevisionId, mutateRemoteRevisionLastUpdatedAt, mutateRemoteRevisionLastUpdateUser]);
 
   const saveAndReturnToViewHandler = useCallback(async(opts: {slackChannels: string, overwriteScopesOfDescendants?: boolean}) => {
     const page = await save(opts);

+ 4 - 1
apps/app/src/stores/page.tsx

@@ -74,9 +74,12 @@ export const useSWRxCurrentPage = (initialData?: IPagePopulatedToShowRevision|nu
       return true;
     }
 
-    if (initialData.revision?._id !== cachedData?.revision?._id) {
+    // mutate when the empty page has updated
+    if (cachedData?.revision == null && initialData.revision != null) {
       return true;
     }
+
+    return false;
   })();
 
   useEffect(() => {