@@ -21,6 +21,66 @@ declare const __ALSes_PROMISE__: Promise<null | {
21
21
requestContextAsyncLocalStorage : AsyncLocalStorage < unknown > ;
22
22
} > ;
23
23
24
+ const originalDefineProperty = Object . defineProperty ;
25
+
26
+ const patchedDefineProperty = (
27
+ ...args : Parameters < typeof Object . defineProperty < unknown > >
28
+ ) => {
29
+ const target = args [ 0 ] ;
30
+ const key = args [ 1 ] ;
31
+ // Next.js defined an __import_unsupported global property as non configurable
32
+ // with next-on-pages this apps try to re-define this property multiple times,
33
+ // so here we patch `defineProperty` to just ignore re-definition of such property
34
+ const importUnsupportedKey = '__import_unsupported' ;
35
+ if ( key === importUnsupportedKey ) {
36
+ if (
37
+ typeof target === 'object' &&
38
+ target !== null &&
39
+ importUnsupportedKey in target
40
+ ) {
41
+ return ;
42
+ }
43
+ }
44
+ return originalDefineProperty ( ...args ) ;
45
+ } ;
46
+
47
+ global . Object . defineProperty =
48
+ patchedDefineProperty as typeof global . Object . defineProperty ;
49
+
50
+ global . AbortController = class PatchedAbortController extends AbortController {
51
+ constructor ( ) {
52
+ try {
53
+ super ( ) ;
54
+ } catch ( e ) {
55
+ if (
56
+ e instanceof Error &&
57
+ e . message . includes ( 'Disallowed operation called within global scope' )
58
+ ) {
59
+ // Next.js attempted to create an AbortController in the global scope
60
+ // let's return something that looks like an AbortController but with
61
+ // noop functionalities
62
+ return {
63
+ signal : {
64
+ aborted : false ,
65
+ reason : null ,
66
+ onabort : ( ) => {
67
+ /* empty */
68
+ } ,
69
+ throwIfAborted : ( ) => {
70
+ /* empty */
71
+ } ,
72
+ } as unknown as AbortSignal ,
73
+ abort ( ) {
74
+ /* empty */
75
+ } ,
76
+ } ;
77
+ } else {
78
+ throw e ;
79
+ }
80
+ }
81
+ }
82
+ } ;
83
+
24
84
export default {
25
85
async fetch ( request , env , ctx ) {
26
86
setupRoutesIsolation ( ) ;
0 commit comments