ryoji-s 2 лет назад
Родитель
Сommit
484c3efba5
2 измененных файлов с 6 добавлено и 8 удалено
  1. 1 1
      apps/app/src/pages/utils/commons.ts
  2. 5 7
      apps/app/src/server/models/page.ts

+ 1 - 1
apps/app/src/pages/utils/commons.ts

@@ -180,7 +180,7 @@ export const skipSSR = async(page: PageDocument): Promise<boolean> => {
   const latestRevisionBodyLength = await page.getLatestRevisionBodyLength();
 
   if (latestRevisionBodyLength == null) {
-    return false;
+    return true;
   }
 
   const { configManager } = await import('~/server/service/config-manager');

+ 5 - 7
apps/app/src/server/models/page.ts

@@ -2,7 +2,9 @@
 
 import nodePath from 'path';
 
-import { HasObjectId, pagePathUtils, pathUtils } from '@growi/core';
+import {
+  HasObjectId, isPopulated, pagePathUtils, pathUtils,
+} from '@growi/core';
 import { collectAncestorPaths } from '@growi/core/dist/utils/page-path-utils/collect-ancestor-paths';
 import escapeStringRegexp from 'escape-string-regexp';
 import mongoose, {
@@ -985,14 +987,10 @@ schema.methods.calculateAndUpdateLatestRevisionBodyLength = async function(this:
     return;
   }
 
-  // Infer the type as Omit<PageDocument, never> due to the population
-  // Cast the type back to PageDocument to restore the original type
   // eslint-disable-next-line rulesdir/no-populate
-  const populatedPageDocument = await this.populate('revision', 'body') as PageDocument;
+  const populatedPageDocument = await this.populate<PageDocument>('revision', 'body');
 
-  if (typeof populatedPageDocument.revision === 'string') {
-    throw new Error('Failed to populate revision field in the page document.');
-  }
+  assert(isPopulated(populatedPageDocument.revision));
 
   this.latestRevisionBodyLength = populatedPageDocument.revision.body.length;
   await this.save();