File tree Expand file tree Collapse file tree 2 files changed +24
-11
lines changed
Expand file tree Collapse file tree 2 files changed +24
-11
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ export async function getPageDocument(
4242 }
4343
4444 // Pre-fetch the document to start filling the cache before we migrate to this API.
45- if ( isInPercentRollout ( space . id , 10 ) ) {
45+ if ( isInPercentRollout ( space . id , 10 ) || process . env . VERCEL_ENV === 'preview' ) {
4646 await waitUntil (
4747 getDataOrNull (
4848 dataFetcher . getRevisionPageDocument ( {
Original file line number Diff line number Diff line change 11import type { ExecutionContext , IncomingRequestCfProperties } from '@cloudflare/workers-types' ;
22import { getCloudflareContext as getCloudflareContextV2 } from '@v2/lib/data/cloudflare' ;
3+ import { GITBOOK_RUNTIME } from '@v2/lib/env' ;
34import { isV2 } from './v2' ;
45
56let pendings : Array < Promise < unknown > > = [ ] ;
@@ -49,20 +50,32 @@ export async function waitUntil(promise: Promise<unknown>) {
4950 return ;
5051 }
5152
52- if ( isV2 ( ) ) {
53- const context = getCloudflareContextV2 ( ) ;
54- if ( context ) {
55- context . ctx . waitUntil ( promise ) ;
56- return ;
53+ if ( GITBOOK_RUNTIME === 'cloudflare' ) {
54+ if ( isV2 ( ) ) {
55+ const context = getCloudflareContextV2 ( ) ;
56+ if ( context ) {
57+ context . ctx . waitUntil ( promise ) ;
58+ return ;
59+ }
60+ } else {
61+ const cloudflareContext = await getGlobalContext ( ) ;
62+ if ( 'waitUntil' in cloudflareContext ) {
63+ cloudflareContext . waitUntil ( promise ) ;
64+ return ;
65+ }
5766 }
5867 }
5968
60- const cloudflareContext = await getGlobalContext ( ) ;
61- if ( 'waitUntil' in cloudflareContext ) {
62- cloudflareContext . waitUntil ( promise ) ;
63- } else {
64- await promise ;
69+ if ( GITBOOK_RUNTIME === 'vercel' && isV2 ( ) ) {
70+ // @ts -expect-error - `after` is not exported by `next/server` in next 14
71+ const { after } = await import ( 'next/server' ) ;
72+ if ( typeof after === 'function' ) {
73+ after ( ( ) => promise ) ;
74+ return ;
75+ }
6576 }
77+
78+ await promise ;
6679}
6780
6881/**
You can’t perform that action at this time.
0 commit comments