mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-20 17:43:24 +00:00
Fix crash on Vercel (#3311)
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user