Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallback shim for AbortController #24285

Merged
merged 9 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 0 additions & 138 deletions packages/react-reconciler/src/ReactAbortController.js

This file was deleted.

27 changes: 24 additions & 3 deletions packages/react-reconciler/src/ReactFiberCacheComponent.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,34 @@ import type {ReactContext} from 'shared/ReactTypes';

import {enableCache} from 'shared/ReactFeatureFlags';
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
import AbortController from './ReactAbortController';

import {pushProvider, popProvider} from './ReactFiberNewContext.new';
import * as Scheduler from 'scheduler';

// In environments without AbortController (e.g. tests)
// replace it with a lightweight shim that only has the features we use.
const AbortControllerLocal = enableCache
? typeof AbortController !== 'undefined'
? AbortController
: (function AbortControllerShim() {
this.listeners = [];
this.signal = {
aborted: false,
};

this.signal.addEventListener = (type, listener) => {
this.listeners.push(listener);
};

this.abort = () => {
this.signal.aborted = true;
this.listeners.forEach(listener => listener());
};
}: AbortController)
rickhanlonii marked this conversation as resolved.
Show resolved Hide resolved
: (null: any);

export type Cache = {|
controller: AbortController,
controller: AbortControllerLocal,
data: Map<() => mixed, mixed>,
refCount: number,
|};
Expand Down Expand Up @@ -67,7 +88,7 @@ export function createCache(): Cache {
return (null: any);
}
const cache: Cache = {
controller: new AbortController(),
controller: new AbortControllerLocal(),
data: new Map(),
refCount: 0,
};
Expand Down