Explorar el Código

fix sharelink

Yuki Takei hace 7 meses
padre
commit
96a77e1614

+ 6 - 6
apps/app/src/pages/general-page/superjson/page-to-show-revision-with-meta.ts

@@ -1,4 +1,3 @@
-import { isIPageInfo } from '@growi/core';
 import type {
   IDataWithMeta,
 } from '@growi/core';
@@ -6,7 +5,7 @@ import superjson from 'superjson';
 
 import type { IPageToShowRevisionWithMeta } from '../types';
 
-type IPageToShowRevisionWithMetaSerialized = IDataWithMeta<string, string>;
+type IPageToShowRevisionWithMetaSerialized = IDataWithMeta<string, string | undefined>;
 
 let isRegistered = false;
 
@@ -16,14 +15,15 @@ export const registerPageToShowRevisionWithMeta = (): void => {
   superjson.registerCustom<IPageToShowRevisionWithMeta, IPageToShowRevisionWithMetaSerialized>(
     {
       isApplicable: (v): v is IPageToShowRevisionWithMeta => {
-        return v?.data != null
-          && v?.data.toObject != null
-          && isIPageInfo(v.meta);
+        const data = v?.data;
+        return data != null
+          && data.toObject != null
+          && data.revision != null && typeof data.revision === 'object';
       },
       serialize: (v) => {
         return {
           data: superjson.stringify(v.data.toObject()),
-          meta: superjson.stringify(v.meta),
+          meta: v.meta != null ? superjson.stringify(v.meta) : undefined,
         };
       },
       deserialize: (v) => {

+ 0 - 6
apps/app/src/pages/general-page/type-guards.ts

@@ -31,12 +31,6 @@ export function isValidInitialAndSameRouteProps(props: unknown): props is Initia
     return false;
   }
 
-  // SSRProps
-  if (typeof p.skipSSR !== 'boolean') {
-    logger.warn('isValidInitialAndSameRouteProps: skipSSR is not a boolean', { skipSSR: p.skipSSR });
-    return false;
-  }
-
   // InitialProps specific page state
   if (typeof p.isNotFound !== 'boolean') {
     logger.warn('isValidInitialAndSameRouteProps: isNotFound is not a boolean', { isNotFound: p.isNotFound });

+ 7 - 4
apps/app/src/pages/share/[[...path]]/page-data-props.ts

@@ -8,9 +8,7 @@ import type { IShareLink } from '~/interfaces/share-link';
 import type { PageModel } from '~/server/models/page';
 import type { ShareLinkModel } from '~/server/models/share-link';
 
-import type { InitialProps } from '../../general-page';
-
-import type { ShareLinkPageProps } from './types';
+import type { ShareLinkInitialProps } from './types';
 
 
 let mongooseModel: typeof model;
@@ -18,7 +16,7 @@ let Page: PageModel;
 let ShareLink: ShareLinkModel;
 
 export const getPageDataForInitial = async(context: GetServerSidePropsContext):
-    Promise<GetServerSidePropsResult<Pick<InitialProps, 'isNotFound' | 'pageWithMeta' | 'skipSSR'> & ShareLinkPageProps>> => {
+    Promise<GetServerSidePropsResult<ShareLinkInitialProps>> => {
 
   const req = context.req as CrowiRequest;
   const { crowi, params } = req;
@@ -41,6 +39,8 @@ export const getPageDataForInitial = async(context: GetServerSidePropsContext):
       props: {
         isNotFound: true,
         pageWithMeta: null,
+        isExpired: undefined,
+        shareLink: undefined,
       },
     };
   }
@@ -52,6 +52,7 @@ export const getPageDataForInitial = async(context: GetServerSidePropsContext):
         isNotFound: false,
         pageWithMeta: null,
         isExpired: true,
+        shareLink,
       },
     };
   }
@@ -65,6 +66,8 @@ export const getPageDataForInitial = async(context: GetServerSidePropsContext):
       props: {
         isNotFound: true,
         pageWithMeta: null,
+        isExpired: undefined,
+        shareLink: undefined,
       },
     };
   }

+ 16 - 11
apps/app/src/pages/share/[[...path]]/types.ts

@@ -1,13 +1,18 @@
 import type { IShareLinkHasId } from '~/interfaces/share-link';
+import type { InitialProps } from '~/pages/general-page';
 
-export type ShareLinkInitialProps = {
-  isNotFound: true,
-  isExpired: undefined
-  shareLink: undefined,
-} | {
-  isExpired: true,
-  shareLink: undefined,
-} | {
-  isExpired: false,
-  shareLink: IShareLinkHasId,
-};
+export type ShareLinkInitialProps = Pick<InitialProps, 'pageWithMeta' | 'skipSSR'> & (
+  {
+    isNotFound: true,
+    isExpired: undefined,
+    shareLink: undefined,
+  } | {
+    isNotFound: false,
+    isExpired: true,
+    shareLink: IShareLinkHasId,
+  } | {
+    isNotFound: false,
+    isExpired: false,
+    shareLink: IShareLinkHasId,
+  }
+);