File tree Expand file tree Collapse file tree 4 files changed +46
-9
lines changed Expand file tree Collapse file tree 4 files changed +46
-9
lines changed Original file line number Diff line number Diff line change 1212// Polyfills for test environment
1313global . ReadableStream = require ( 'web-streams-polyfill/ponyfill/es6' ) . ReadableStream ;
1414global . TextEncoder = require ( 'util' ) . TextEncoder ;
15- global . AbortController = require ( 'abort-controller' ) ;
1615
1716let React ;
1817let ReactDOMFizzServer ;
Original file line number Diff line number Diff line change @@ -15,8 +15,29 @@ import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
1515import { pushProvider , popProvider } from './ReactFiberNewContext.new' ;
1616import * as Scheduler from 'scheduler' ;
1717
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+
1839export type Cache = { |
19- controller : AbortController ,
40+ controller : AbortControllerLocal ,
2041 data : Map < ( ) => mixed , mixed> ,
2142 refCount : number ,
2243| } ;
@@ -66,7 +87,7 @@ export function createCache(): Cache {
6687 return ( null : any ) ;
6788 }
6889 const cache : Cache = {
69- controller : new AbortController ( ) ,
90+ controller : new AbortControllerLocal ( ) ,
7091 data : new Map ( ) ,
7192 refCount : 0 ,
7293 } ;
Original file line number Diff line number Diff line change @@ -15,8 +15,29 @@ import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
1515import { pushProvider , popProvider } from './ReactFiberNewContext.old' ;
1616import * as Scheduler from 'scheduler' ;
1717
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+
1839export type Cache = { |
19- controller : AbortController ,
40+ controller : AbortControllerLocal ,
2041 data : Map < ( ) => mixed , mixed> ,
2142 refCount : number ,
2243| } ;
@@ -66,7 +87,7 @@ export function createCache(): Cache {
6687 return ( null : any ) ;
6788 }
6889 const cache : Cache = {
69- controller : new AbortController ( ) ,
90+ controller : new AbortControllerLocal ( ) ,
7091 data : new Map ( ) ,
7192 refCount : 0 ,
7293 } ;
Original file line number Diff line number Diff line change 11/* eslint-disable */
22
3- const AbortController = require ( 'abort-controller' ) ;
4-
53const NODE_ENV = process . env . NODE_ENV ;
64if ( NODE_ENV !== 'development' && NODE_ENV !== 'production' ) {
75 throw new Error ( 'NODE_ENV must either be set to development or production.' ) ;
@@ -23,8 +21,6 @@ global.__EXPERIMENTAL__ =
2321
2422global . __VARIANT__ = ! ! process . env . VARIANT ;
2523
26- global . AbortController = AbortController ;
27-
2824if ( typeof window !== 'undefined' ) {
2925 global . requestIdleCallback = function ( callback ) {
3026 return setTimeout ( ( ) => {
You can’t perform that action at this time.
0 commit comments