Shun Miyazawa 1 rok temu
rodzic
commit
c035c466b1

+ 2 - 0
apps/app/src/components/PageView/PageView.tsx

@@ -128,6 +128,8 @@ export const PageView = (props: Props): JSX.Element => {
     const markdown = page.revision.body;
     const rendererOptions = viewOptions ?? generateSSRViewOptions(rendererConfig, pagePath);
 
+    console.log('markdown', markdown);
+
     return (
       <>
         <PageContentsUtilities />

+ 4 - 1
apps/app/src/pages/[[...path]].page.tsx

@@ -190,6 +190,7 @@ type Props = CommonProps & {
   yjsData: CurrentPageYjsData,
 
   rendererConfig: RendererConfig,
+  isPastRevisionSelected: boolean,
 };
 
 const Page: NextPageWithLayout<Props> = (props: Props) => {
@@ -250,7 +251,7 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
 
   useCurrentPathname(props.currentPathname);
 
-  const { data: currentPage } = useSWRxCurrentPage(pageWithMeta?.data ?? null); // store initial data
+  const { data: currentPage } = useSWRxCurrentPage(pageWithMeta?.data ?? null, props.isPastRevisionSelected); // store initial data
 
   const { trigger: mutateCurrentPage } = useSWRMUTxCurrentPage();
   const { trigger: mutateCurrentPageYjsDataFromApi } = useSWRMUTxCurrentPageYjsData();
@@ -432,6 +433,8 @@ async function injectPageData(context: GetServerSidePropsContext, props: Props):
   const { crowi } = req;
   const { revisionId } = req.query;
 
+  props.isPastRevisionSelected = revisionId != null;
+
   const Page = crowi.model('Page') as PageModel;
   const PageRedirect = mongooseModel('PageRedirect') as PageRedirectModel;
   const { pageService, configManager } = crowi;

+ 10 - 7
apps/app/src/stores/page.tsx

@@ -54,7 +54,9 @@ export const useTemplateBodyData = (initialData?: string): SWRResponse<string, E
 };
 
 /** "useSWRxCurrentPage" is intended for initial data retrieval only. Use "useSWRMUTxCurrentPage" for revalidation */
-export const useSWRxCurrentPage = (initialData?: IPagePopulatedToShowRevision|null): SWRResponse<IPagePopulatedToShowRevision|null> => {
+export const useSWRxCurrentPage = (
+    initialData?: IPagePopulatedToShowRevision|null, isPastRevisionSelected = false,
+): SWRResponse<IPagePopulatedToShowRevision|null> => {
   const key = 'currentPage';
 
   const { cache } = useSWRConfig();
@@ -81,23 +83,24 @@ export const useSWRxCurrentPage = (initialData?: IPagePopulatedToShowRevision|nu
       return true;
     }
 
-    // mutate When a different revision is opened
-    if (cachedData.revision?._id != null && initialData.revision?._id != null && cachedData.revision._id !== initialData.revision._id) {
-      return true;
-    }
+    // // mutate When a different revision is opened
+    // if (cachedData.revision?._id != null && initialData.revision?._id != null && cachedData.revision._id !== initialData.revision._id) {
+    //   console.log('initialData', initialData);
+    //   return true;
+    // }
 
     return false;
   })();
 
   useEffect(() => {
-    if (shouldMutate) {
+    if (shouldMutate || isPastRevisionSelected) {
       mutate(key, initialData, {
         optimisticData: initialData,
         populateCache: true,
         revalidate: false,
       });
     }
-  }, [initialData, key, shouldMutate]);
+  }, [initialData, isPastRevisionSelected, key, shouldMutate]);
 
   return useSWR(key, null, {
     keepPreviousData: true,