Fix crash on Vercel (#3311)

This commit is contained in:
Samy Pessé
2025-06-12 23:37:38 +02:00
committed by GitHub
parent fecdbe8dde
commit da67711c90
2 changed files with 24 additions and 11 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ export async function getPageDocument(
}
// Pre-fetch the document to start filling the cache before we migrate to this API.
if (isInPercentRollout(space.id, 10)) {
if (isInPercentRollout(space.id, 10) || process.env.VERCEL_ENV === 'preview') {
await waitUntil(
getDataOrNull(
dataFetcher.getRevisionPageDocument({
+23 -10
View File
@@ -1,5 +1,6 @@
import type { ExecutionContext, IncomingRequestCfProperties } from '@cloudflare/workers-types';
import { getCloudflareContext as getCloudflareContextV2 } from '@v2/lib/data/cloudflare';
import { GITBOOK_RUNTIME } from '@v2/lib/env';
import { isV2 } from './v2';
let pendings: Array<Promise<unknown>> = [];
@@ -49,20 +50,32 @@ export async function waitUntil(promise: Promise<unknown>) {
return;
}
if (isV2()) {
const context = getCloudflareContextV2();
if (context) {
context.ctx.waitUntil(promise);
if (GITBOOK_RUNTIME === 'cloudflare') {
if (isV2()) {
const context = getCloudflareContextV2();
if (context) {
context.ctx.waitUntil(promise);
return;
}
} else {
const cloudflareContext = await getGlobalContext();
if ('waitUntil' in cloudflareContext) {
cloudflareContext.waitUntil(promise);
return;
}
}
}
if (GITBOOK_RUNTIME === 'vercel' && isV2()) {
// @ts-expect-error - `after` is not exported by `next/server` in next 14
const { after } = await import('next/server');
if (typeof after === 'function') {
after(() => promise);
return;
}
}
const cloudflareContext = await getGlobalContext();
if ('waitUntil' in cloudflareContext) {
cloudflareContext.waitUntil(promise);
} else {
await promise;
}
await promise;
}
/**