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

Don't fetch if you are on a shared page

Shun Miyazawa 3 лет назад
Родитель
Сommit
d7e687d357
1 измененных файлов с 4 добавлено и 3 удалено
  1. 4 3
      packages/app/src/stores/page.tsx

+ 4 - 3
packages/app/src/stores/page.tsx

@@ -28,13 +28,14 @@ export const useSWRxPage = (
     revisionId?: string,
     revisionId?: string,
     initialData?: IPagePopulatedToShowRevision|null,
     initialData?: IPagePopulatedToShowRevision|null,
 ): SWRResponse<IPagePopulatedToShowRevision|null, Error> => {
 ): SWRResponse<IPagePopulatedToShowRevision|null, Error> => {
+
   const { data: pathname } = useCurrentPathname();
   const { data: pathname } = useCurrentPathname();
   const isSharedPage = _isSharedPage(pathname ?? '');
   const isSharedPage = _isSharedPage(pathname ?? '');
+  const shouldFetch = pageId != null && !isSharedPage;
 
 
   const swrResponse = useSWRImmutable<IPagePopulatedToShowRevision|null, Error>(
   const swrResponse = useSWRImmutable<IPagePopulatedToShowRevision|null, Error>(
-    pageId != null ? ['/page', pageId, shareLinkId, revisionId] : null,
-    // eslint-disable-next-line max-len
-    isSharedPage ? null : (endpoint, pageId, shareLinkId, revisionId) => apiv3Get<{ page: IPagePopulatedToShowRevision }>(endpoint, { pageId, shareLinkId, revisionId })
+    shouldFetch ? ['/page', pageId, shareLinkId, revisionId] : null,
+    (endpoint, pageId, shareLinkId, revisionId) => apiv3Get<{ page: IPagePopulatedToShowRevision }>(endpoint, { pageId, shareLinkId, revisionId })
       .then(result => result.data.page)
       .then(result => result.data.page)
       .catch((errs) => {
       .catch((errs) => {
         if (!Array.isArray(errs)) { throw Error('error is not array') }
         if (!Array.isArray(errs)) { throw Error('error is not array') }