Просмотр исходного кода

Merge remote-tracking branch 'origin/master' into imprv/ssr

Yuki Takei 3 лет назад
Родитель
Сommit
cb00989a30
2 измененных файлов с 12 добавлено и 3 удалено
  1. 6 1
      packages/app/src/pages/[[...path]].page.tsx
  2. 6 2
      packages/app/src/stores/editor.tsx

+ 6 - 1
packages/app/src/pages/[[...path]].page.tsx

@@ -264,7 +264,7 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
 
 
   useSWRxCurrentPage(pageWithMeta?.data ?? null); // store initial data
   useSWRxCurrentPage(pageWithMeta?.data ?? null); // store initial data
 
 
-  useEditingMarkdown(revisionBody);
+  const { mutate: mutateEditingMarkdown } = useEditingMarkdown();
 
 
   const { data: grantData } = useSWRxIsGrantNormalized(pageId);
   const { data: grantData } = useSWRxIsGrantNormalized(pageId);
   const { mutate: mutateSelectedGrant } = useSelectedGrant();
   const { mutate: mutateSelectedGrant } = useSelectedGrant();
@@ -293,6 +293,11 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
     }
     }
   }, [props.currentPathname, router]);
   }, [props.currentPathname, router]);
 
 
+  // initialize mutateEditingMarkdown only once per page
+  useEffect(() => {
+    mutateEditingMarkdown(revisionBody);
+  }, [mutateEditingMarkdown, revisionBody]);
+
   const title = generateCustomTitleForPage(props, pagePath);
   const title = generateCustomTitleForPage(props, pagePath);
 
 
   // TODO: show SSR body
   // TODO: show SSR body

+ 6 - 2
packages/app/src/stores/editor.tsx

@@ -10,15 +10,19 @@ import { IEditorSettings } from '~/interfaces/editor-settings';
 import { SlackChannels } from '~/interfaces/user-trigger-notification';
 import { SlackChannels } from '~/interfaces/user-trigger-notification';
 
 
 import {
 import {
+  useCurrentPathname,
   useCurrentUser, useDefaultIndentSize, useIsGuestUser,
   useCurrentUser, useDefaultIndentSize, useIsGuestUser,
 } from './context';
 } from './context';
 // import { localStorageMiddleware } from './middlewares/sync-to-storage';
 // import { localStorageMiddleware } from './middlewares/sync-to-storage';
-import { useCurrentPagePath, useSWRxTagsInfo } from './page';
+import { useSWRxTagsInfo } from './page';
 import { useStaticSWR } from './use-static-swr';
 import { useStaticSWR } from './use-static-swr';
 
 
 
 
 export const useEditingMarkdown = (initialData?: string): SWRResponse<string, Error> => {
 export const useEditingMarkdown = (initialData?: string): SWRResponse<string, Error> => {
-  const { data: currentPagePath } = useCurrentPagePath();
+  // need to include useCurrentPathname not useCurrentPagePath
+  // https://github.com/weseek/growi/pull/7301
+  const { data: currentPagePath } = useCurrentPathname();
+
   return useStaticSWR(['editingMarkdown', currentPagePath], initialData);
   return useStaticSWR(['editingMarkdown', currentPagePath], initialData);
 };
 };