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(
42
42
}
43
43
44
44
// 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' ) {
46
46
await waitUntil (
47
47
getDataOrNull (
48
48
dataFetcher . getRevisionPageDocument ( {
Original file line number Diff line number Diff line change 1
1
import type { ExecutionContext , IncomingRequestCfProperties } from '@cloudflare/workers-types' ;
2
2
import { getCloudflareContext as getCloudflareContextV2 } from '@v2/lib/data/cloudflare' ;
3
+ import { GITBOOK_RUNTIME } from '@v2/lib/env' ;
3
4
import { isV2 } from './v2' ;
4
5
5
6
let pendings : Array < Promise < unknown > > = [ ] ;
@@ -49,20 +50,32 @@ export async function waitUntil(promise: Promise<unknown>) {
49
50
return ;
50
51
}
51
52
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
+ }
57
66
}
58
67
}
59
68
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
+ }
65
76
}
77
+
78
+ await promise ;
66
79
}
67
80
68
81
/**
You can’t perform that action at this time.
0 commit comments