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

load current yjs data even when SSR

Yuki Takei 1 год назад
Родитель
Сommit
a30ce6cb0c
1 измененных файлов с 7 добавлено и 1 удалено
  1. 7 1
      apps/app/src/pages/[[...path]].page.tsx

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

@@ -282,7 +282,6 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
       const mutatePageData = async() => {
       const mutatePageData = async() => {
         const pageData = await mutateCurrentPage();
         const pageData = await mutateCurrentPage();
         mutateEditingMarkdown(pageData?.revision?.body);
         mutateEditingMarkdown(pageData?.revision?.body);
-        mutateCurrentPageYjsDataFromApi();
       };
       };
 
 
       // If skipSSR is true, use the API to retrieve page data.
       // If skipSSR is true, use the API to retrieve page data.
@@ -294,6 +293,13 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
     mutateCurrentPageYjsDataFromApi, mutateEditingMarkdown, props.isNotFound, props.skipSSR,
     mutateCurrentPageYjsDataFromApi, mutateEditingMarkdown, props.isNotFound, props.skipSSR,
   ]);
   ]);
 
 
+  // Load current yjs data
+  useEffect(() => {
+    if (currentPageId != null && revisionId != null && !props.isNotFound) {
+      mutateCurrentPageYjsDataFromApi();
+    }
+  }, [currentPageId, mutateCurrentPageYjsDataFromApi, props.isNotFound, revisionId]);
+
   // sync pathname by Shallow Routing https://nextjs.org/docs/routing/shallow-routing
   // sync pathname by Shallow Routing https://nextjs.org/docs/routing/shallow-routing
   useEffect(() => {
   useEffect(() => {
     const decodedURI = decodeURI(window.location.pathname);
     const decodedURI = decodeURI(window.location.pathname);