Commit 8dcedba 1 parent b86baa1 commit 8dcedba Copy full SHA for 8dcedba
File tree 4 files changed +46
-9
lines changed
4 files changed +46
-9
lines changed Original file line number Diff line number Diff line change 12
12
// Polyfills for test environment
13
13
global . ReadableStream = require ( 'web-streams-polyfill/ponyfill/es6' ) . ReadableStream ;
14
14
global . TextEncoder = require ( 'util' ) . TextEncoder ;
15
- global . AbortController = require ( 'abort-controller' ) ;
16
15
17
16
let React ;
18
17
let ReactDOMFizzServer ;
Original file line number Diff line number Diff line change @@ -15,8 +15,29 @@ import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
15
15
import { pushProvider , popProvider } from './ReactFiberNewContext.new' ;
16
16
import * as Scheduler from 'scheduler' ;
17
17
18
+ // In environments without AbortController (e.g. tests)
19
+ // replace it with a lightweight shim that only has the features we use.
20
+ const AbortControllerLocal = enableCache
21
+ ? typeof AbortController !== 'undefined'
22
+ ? AbortController
23
+ : ( function AbortControllerShim ( ) {
24
+ const listeners = [ ] ;
25
+ const signal = ( this . signal = {
26
+ aborted : false ,
27
+ addEventListener : ( type , listener ) => {
28
+ listeners . push ( listener ) ;
29
+ } ,
30
+ } ) ;
31
+
32
+ this . abort = ( ) => {
33
+ signal . aborted = true ;
34
+ listeners . forEach ( listener => listener ( ) ) ;
35
+ } ;
36
+ } : AbortController )
37
+ : ( null : any ) ;
38
+
18
39
export type Cache = { |
19
- controller : AbortController ,
40
+ controller : AbortControllerLocal ,
20
41
data : Map < ( ) => mixed , mixed> ,
21
42
refCount : number ,
22
43
| } ;
@@ -66,7 +87,7 @@ export function createCache(): Cache {
66
87
return ( null : any ) ;
67
88
}
68
89
const cache : Cache = {
69
- controller : new AbortController ( ) ,
90
+ controller : new AbortControllerLocal ( ) ,
70
91
data : new Map ( ) ,
71
92
refCount : 0 ,
72
93
} ;
Original file line number Diff line number Diff line change @@ -15,8 +15,29 @@ import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
15
15
import { pushProvider , popProvider } from './ReactFiberNewContext.old' ;
16
16
import * as Scheduler from 'scheduler' ;
17
17
18
+ // In environments without AbortController (e.g. tests)
19
+ // replace it with a lightweight shim that only has the features we use.
20
+ const AbortControllerLocal = enableCache
21
+ ? typeof AbortController !== 'undefined'
22
+ ? AbortController
23
+ : ( function AbortControllerShim ( ) {
24
+ const listeners = [ ] ;
25
+ const signal = ( this . signal = {
26
+ aborted : false ,
27
+ addEventListener : ( type , listener ) => {
28
+ listeners . push ( listener ) ;
29
+ } ,
30
+ } ) ;
31
+
32
+ this . abort = ( ) => {
33
+ signal . aborted = true ;
34
+ listeners . forEach ( listener => listener ( ) ) ;
35
+ } ;
36
+ } : AbortController )
37
+ : ( null : any ) ;
38
+
18
39
export type Cache = { |
19
- controller : AbortController ,
40
+ controller : AbortControllerLocal ,
20
41
data : Map < ( ) => mixed , mixed> ,
21
42
refCount : number ,
22
43
| } ;
@@ -66,7 +87,7 @@ export function createCache(): Cache {
66
87
return ( null : any ) ;
67
88
}
68
89
const cache : Cache = {
69
- controller : new AbortController ( ) ,
90
+ controller : new AbortControllerLocal ( ) ,
70
91
data : new Map ( ) ,
71
92
refCount : 0 ,
72
93
} ;
Original file line number Diff line number Diff line change 1
1
/* eslint-disable */
2
2
3
- const AbortController = require ( 'abort-controller' ) ;
4
-
5
3
const NODE_ENV = process . env . NODE_ENV ;
6
4
if ( NODE_ENV !== 'development' && NODE_ENV !== 'production' ) {
7
5
throw new Error ( 'NODE_ENV must either be set to development or production.' ) ;
@@ -23,8 +21,6 @@ global.__EXPERIMENTAL__ =
23
21
24
22
global . __VARIANT__ = ! ! process . env . VARIANT ;
25
23
26
- global . AbortController = AbortController ;
27
-
28
24
if ( typeof window !== 'undefined' ) {
29
25
global . requestIdleCallback = function ( callback ) {
30
26
return setTimeout ( ( ) => {
You can’t perform that action at this time.
0 commit comments