Explorar el Código

Don't fetch if you are on a shared page

Shun Miyazawa hace 3 años
padre
commit
d7e687d357
Se han modificado 1 ficheros con 4 adiciones y 3 borrados
  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') }