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

Merge remote-tracking branch 'origin/dev/7.0.x'

Yuki Takei 1 год назад
Родитель
Сommit
d4b772a731

+ 2 - 2
apps/app/src/client/components/ReactMarkdownComponents/Header.tsx

@@ -66,7 +66,7 @@ export const Header = (props: HeaderProps): JSX.Element => {
   const { data: isReadOnlyUser } = useIsReadOnlyUser();
   const { data: isReadOnlyUser } = useIsReadOnlyUser();
   const { data: isSharedUser } = useIsSharedUser();
   const { data: isSharedUser } = useIsSharedUser();
   const { data: shareLinkId } = useShareLinkId();
   const { data: shareLinkId } = useShareLinkId();
-  const { data: currentPageYjsData } = useCurrentPageYjsData();
+  const { data: currentPageYjsData, isLoading: isLoadingCurrentPageYjsData } = useCurrentPageYjsData();
 
 
   const router = useRouter();
   const router = useRouter();
 
 
@@ -117,7 +117,7 @@ export const Header = (props: HeaderProps): JSX.Element => {
   // It will be possible to address this TODO ySyncAnnotation become available for import.
   // It will be possible to address this TODO ySyncAnnotation become available for import.
   // Ref: https://github.com/yjs/y-codemirror.next/pull/30
   // Ref: https://github.com/yjs/y-codemirror.next/pull/30
   const showEditButton = !isGuestUser && !isReadOnlyUser && !isSharedUser && shareLinkId == null
   const showEditButton = !isGuestUser && !isReadOnlyUser && !isSharedUser && shareLinkId == null
-                            && currentPageYjsData?.hasYdocsNewerThanLatestRevision === false;
+                            && (!isLoadingCurrentPageYjsData && !currentPageYjsData?.hasYdocsNewerThanLatestRevision);
 
 
   return (
   return (
     <>
     <>

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

@@ -290,7 +290,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.
@@ -302,6 +301,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);

+ 1 - 1
apps/app/src/stores/yjs.ts

@@ -43,7 +43,7 @@ export const useSWRMUTxCurrentPageYjsData = (): SWRMutationResponse<CurrentPageY
 
 
   return useSWRMutation(
   return useSWRMutation(
     key,
     key,
-    ([endpoint]) => apiv3Get<{ yjsData: CurrentPageYjsData }>(endpoint).then(result => result.data.yjsData),
+    endpoint => apiv3Get<{ yjsData: CurrentPageYjsData }>(endpoint).then(result => result.data.yjsData),
     { populateCache: true, revalidate: false },
     { populateCache: true, revalidate: false },
   );
   );
 };
 };