Skip to content

Commit 75b6921

Browse files
authored
Remove dead code from modern event system (facebook#19233)
* Remove dead code from modern event system * Remove SSR dependency on EventPluginRegistry
1 parent 9fba65e commit 75b6921

38 files changed

+237
-755
lines changed

packages/react-dom/src/client/ReactDOM.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type {ReactNodeList} from 'shared/ReactTypes';
1111
import type {Container} from './ReactDOMHostConfig';
1212

1313
import '../shared/checkReact';
14-
import './ReactDOMClientInjection';
1514
import {
1615
findDOMNode,
1716
render,
@@ -39,10 +38,7 @@ import {
3938
} from 'react-reconciler/src/ReactFiberReconciler';
4039
import {createPortal as createPortalImpl} from 'react-reconciler/src/ReactPortal';
4140
import {canUseDOM} from 'shared/ExecutionEnvironment';
42-
import {
43-
eventNameDispatchConfigs,
44-
injectEventPluginsByName,
45-
} from '../legacy-events/EventPluginRegistry';
41+
import {eventNameDispatchConfigs} from '../events/EventPluginRegistry';
4642
import ReactVersion from 'shared/ReactVersion';
4743
import invariant from 'shared/invariant';
4844
import {
@@ -57,7 +53,6 @@ import {
5753
getClosestInstanceFromNode,
5854
} from './ReactDOMComponentTree';
5955
import {restoreControlledState} from './ReactDOMComponent';
60-
import {dispatchEvent} from '../events/ReactDOMEventListener';
6156
import {
6257
setAttemptSynchronousHydration,
6358
setAttemptUserBlockingHydration,
@@ -180,11 +175,9 @@ const Internals = {
180175
getInstanceFromNode,
181176
getNodeFromInstance,
182177
getFiberCurrentPropsFromNode,
183-
injectEventPluginsByName,
184178
eventNameDispatchConfigs,
185179
enqueueStateRestore,
186180
restoreStateIfNeeded,
187-
dispatchEvent,
188181
flushPassiveEffects,
189182
IsThisRendererActing,
190183
],

packages/react-dom/src/client/ReactDOMClientInjection.js

-24
This file was deleted.

packages/react-dom/src/client/ReactDOMComponent.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
* @flow
88
*/
99

10-
import {registrationNameModules} from '../legacy-events/EventPluginRegistry';
10+
import {
11+
registrationNameModules,
12+
possibleRegistrationNames,
13+
} from '../events/EventPluginRegistry';
1114
import {canUseDOM} from 'shared/ExecutionEnvironment';
1215
import invariant from 'shared/invariant';
1316
import {
@@ -129,7 +132,10 @@ if (__DEV__) {
129132
validatePropertiesInDevelopment = function(type, props) {
130133
validateARIAProperties(type, props);
131134
validateInputProperties(type, props);
132-
validateUnknownProperties(type, props, /* canUseEventSystem */ true);
135+
validateUnknownProperties(type, props, {
136+
registrationNameModules,
137+
possibleRegistrationNames,
138+
});
133139
};
134140

135141
// IE 11 parses & normalizes the style attribute as opposed to other

packages/react-dom/src/client/ReactDOMComponentTree.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type {
1717
SuspenseInstance,
1818
Props,
1919
} from './ReactDOMHostConfig';
20-
import type {DOMTopLevelEventType} from '../legacy-events/TopLevelEventTypes';
20+
import type {DOMTopLevelEventType} from '../events/TopLevelEventTypes';
2121

2222
import {
2323
HostComponent,

packages/react-dom/src/client/ReactDOMEventHandle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {DOMTopLevelEventType} from '../legacy-events/TopLevelEventTypes';
10+
import type {DOMTopLevelEventType} from '../events/TopLevelEventTypes';
1111
import type {EventPriority, ReactScopeInstance} from 'shared/ReactTypes';
1212
import type {
1313
ReactDOMEventHandle,

packages/react-dom/src/client/ReactDOMHostConfig.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {TopLevelType} from '../legacy-events/TopLevelEventTypes';
10+
import type {TopLevelType} from '../events/TopLevelEventTypes';
1111
import type {Fiber, FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
1212
import type {
1313
BoundingRect,

packages/react-dom/src/events/DOMEventProperties.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import type {EventPriority} from 'shared/ReactTypes';
1111
import type {
1212
TopLevelType,
1313
DOMTopLevelEventType,
14-
} from '../legacy-events/TopLevelEventTypes';
14+
} from '../events/TopLevelEventTypes';
1515
import type {
1616
DispatchConfig,
1717
CustomDispatchConfig,
18-
} from '../legacy-events/ReactSyntheticEventType';
18+
} from '../events/ReactSyntheticEventType';
1919

2020
import * as DOMTopLevelEventTypes from './DOMTopLevelEventTypes';
2121
import {

packages/react-dom/src/events/DOMModernPluginEventSystem.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* @flow
88
*/
99

10-
import type {AnyNativeEvent} from '../legacy-events/PluginModuleType';
11-
import type {DOMTopLevelEventType} from '../legacy-events/TopLevelEventTypes';
10+
import type {AnyNativeEvent} from '../events/PluginModuleType';
11+
import type {DOMTopLevelEventType} from '../events/TopLevelEventTypes';
1212
import type {
1313
ElementListenerMap,
1414
ElementListenerMapEntry,
@@ -22,14 +22,14 @@ import type {
2222
DispatchQueueItem,
2323
DispatchQueueItemPhase,
2424
DispatchQueueItemPhaseEntry,
25-
} from '../legacy-events/PluginModuleType';
25+
} from '../events/PluginModuleType';
2626
import type {
2727
ReactSyntheticEvent,
2828
CustomDispatchConfig,
29-
} from '../legacy-events/ReactSyntheticEventType';
29+
} from '../events/ReactSyntheticEventType';
3030

31-
import {registrationNameDependencies} from '../legacy-events/EventPluginRegistry';
32-
import {plugins} from '../legacy-events/EventPluginRegistry';
31+
import {registrationNameDependencies} from '../events/EventPluginRegistry';
32+
import {plugins} from '../events/EventPluginRegistry';
3333
import {
3434
PLUGIN_EVENT_SYSTEM,
3535
LEGACY_FB_SUPPORT,

packages/react-dom/src/events/DOMTopLevelEventTypes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
* @flow
88
*/
99

10-
import type {DOMTopLevelEventType} from '../legacy-events/TopLevelEventTypes';
10+
import type {DOMTopLevelEventType} from '../events/TopLevelEventTypes';
1111

1212
import {
1313
unsafeCastStringToDOMTopLevelType,
1414
unsafeCastDOMTopLevelTypeToString,
15-
} from '../legacy-events/TopLevelEventTypes';
15+
} from '../events/TopLevelEventTypes';
1616
import getVendorPrefixedEventName from './getVendorPrefixedEventName';
1717

1818
/**

packages/react-dom/src/events/DeprecatedDOMEventResponderSystem.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
PASSIVE_NOT_SUPPORTED,
1313
RESPONDER_EVENT_SYSTEM,
1414
} from './EventSystemFlags';
15-
import type {AnyNativeEvent} from '../legacy-events/PluginModuleType';
15+
import type {AnyNativeEvent} from '../events/PluginModuleType';
1616
import {
1717
HostComponent,
1818
ScopeComponent,
@@ -25,7 +25,7 @@ import type {
2525
ReactDOMResponderContext,
2626
ReactDOMResponderEvent,
2727
} from '../shared/ReactDOMTypes';
28-
import type {DOMTopLevelEventType} from '../legacy-events/TopLevelEventTypes';
28+
import type {DOMTopLevelEventType} from '../events/TopLevelEventTypes';
2929
import {
3030
batchedEventUpdates,
3131
discreteUpdates,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
import type {DispatchConfig} from './ReactSyntheticEventType';
11+
import type {
12+
AnyNativeEvent,
13+
LegacyPluginModule,
14+
ModernPluginModule,
15+
} from './PluginModuleType';
16+
import ModernBeforeInputEventPlugin from '../events/plugins/ModernBeforeInputEventPlugin';
17+
import ModernChangeEventPlugin from '../events/plugins/ModernChangeEventPlugin';
18+
import ModernEnterLeaveEventPlugin from '../events/plugins/ModernEnterLeaveEventPlugin';
19+
import ModernSelectEventPlugin from '../events/plugins/ModernSelectEventPlugin';
20+
import ModernSimpleEventPlugin from '../events/plugins/ModernSimpleEventPlugin';
21+
22+
import invariant from 'shared/invariant';
23+
24+
/**
25+
* Publishes an event so that it can be dispatched by the supplied plugin.
26+
*
27+
* @param {object} dispatchConfig Dispatch configuration for the event.
28+
* @param {object} PluginModule Plugin publishing the event.
29+
* @return {boolean} True if the event was successfully published.
30+
* @private
31+
*/
32+
function publishEventForPlugin(
33+
dispatchConfig: DispatchConfig,
34+
pluginModule:
35+
| LegacyPluginModule<AnyNativeEvent>
36+
| ModernPluginModule<AnyNativeEvent>,
37+
eventName: string,
38+
): boolean {
39+
invariant(
40+
!eventNameDispatchConfigs.hasOwnProperty(eventName),
41+
'EventPluginRegistry: More than one plugin attempted to publish the same ' +
42+
'event name, `%s`.',
43+
eventName,
44+
);
45+
eventNameDispatchConfigs[eventName] = dispatchConfig;
46+
47+
const phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
48+
if (phasedRegistrationNames) {
49+
for (const phaseName in phasedRegistrationNames) {
50+
if (phasedRegistrationNames.hasOwnProperty(phaseName)) {
51+
const phasedRegistrationName = phasedRegistrationNames[phaseName];
52+
publishRegistrationName(
53+
phasedRegistrationName,
54+
pluginModule,
55+
eventName,
56+
);
57+
}
58+
}
59+
return true;
60+
} else if (dispatchConfig.registrationName) {
61+
publishRegistrationName(
62+
dispatchConfig.registrationName,
63+
pluginModule,
64+
eventName,
65+
);
66+
return true;
67+
}
68+
return false;
69+
}
70+
71+
/**
72+
* Publishes a registration name that is used to identify dispatched events.
73+
*
74+
* @param {string} registrationName Registration name to add.
75+
* @param {object} PluginModule Plugin publishing the event.
76+
* @private
77+
*/
78+
function publishRegistrationName(
79+
registrationName: string,
80+
pluginModule:
81+
| LegacyPluginModule<AnyNativeEvent>
82+
| ModernPluginModule<AnyNativeEvent>,
83+
eventName: string,
84+
): void {
85+
invariant(
86+
!registrationNameModules[registrationName],
87+
'EventPluginRegistry: More than one plugin attempted to publish the same ' +
88+
'registration name, `%s`.',
89+
registrationName,
90+
);
91+
registrationNameModules[registrationName] = pluginModule;
92+
registrationNameDependencies[registrationName] =
93+
pluginModule.eventTypes[eventName].dependencies;
94+
95+
if (__DEV__) {
96+
const lowerCasedName = registrationName.toLowerCase();
97+
possibleRegistrationNames[lowerCasedName] = registrationName;
98+
99+
if (registrationName === 'onDoubleClick') {
100+
possibleRegistrationNames.ondblclick = registrationName;
101+
}
102+
}
103+
}
104+
105+
/**
106+
* Registers plugins so that they can extract and dispatch events.
107+
*/
108+
109+
/**
110+
* Ordered list of injected plugins.
111+
*/
112+
export const plugins = [];
113+
114+
/**
115+
* Mapping from event name to dispatch config
116+
*/
117+
export const eventNameDispatchConfigs = {};
118+
119+
/**
120+
* Mapping from registration name to plugin module
121+
*/
122+
export const registrationNameModules = {};
123+
124+
/**
125+
* Mapping from registration name to event name
126+
*/
127+
export const registrationNameDependencies = {};
128+
129+
/**
130+
* Mapping from lowercase registration names to the properly cased version,
131+
* used to warn in the case of missing event handlers. Available
132+
* only in __DEV__.
133+
* @type {Object}
134+
*/
135+
export const possibleRegistrationNames = __DEV__ ? {} : (null: any);
136+
// Trust the developer to only use possibleRegistrationNames in __DEV__
137+
138+
function injectEventPlugin(pluginModule: ModernPluginModule<any>): void {
139+
plugins.push(pluginModule);
140+
const publishedEvents = pluginModule.eventTypes;
141+
for (const eventName in publishedEvents) {
142+
publishEventForPlugin(publishedEvents[eventName], pluginModule, eventName);
143+
}
144+
}
145+
146+
// TODO: remove top-level side effect.
147+
injectEventPlugin(ModernSimpleEventPlugin);
148+
injectEventPlugin(ModernEnterLeaveEventPlugin);
149+
injectEventPlugin(ModernChangeEventPlugin);
150+
injectEventPlugin(ModernSelectEventPlugin);
151+
injectEventPlugin(ModernBeforeInputEventPlugin);

packages/react-dom/src/events/ReactDOMEventListener.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
* @flow
88
*/
99

10-
import type {AnyNativeEvent} from '../legacy-events/PluginModuleType';
10+
import type {AnyNativeEvent} from '../events/PluginModuleType';
1111
import type {EventPriority} from 'shared/ReactTypes';
1212
import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
1313
import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
14-
import type {DOMTopLevelEventType} from '../legacy-events/TopLevelEventTypes';
14+
import type {DOMTopLevelEventType} from '../events/TopLevelEventTypes';
1515

1616
// Intentionally not named imports because Rollup would use dynamic dispatch for
1717
// CommonJS interop named imports.

packages/react-dom/src/events/ReactDOMEventReplaying.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* @flow
88
*/
99

10-
import type {AnyNativeEvent} from '../legacy-events/PluginModuleType';
10+
import type {AnyNativeEvent} from '../events/PluginModuleType';
1111
import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
12-
import type {DOMTopLevelEventType} from '../legacy-events/TopLevelEventTypes';
12+
import type {DOMTopLevelEventType} from '../events/TopLevelEventTypes';
1313
import type {ElementListenerMap} from '../client/ReactDOMComponentTree';
1414
import type {EventSystemFlags} from './EventSystemFlags';
1515
import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
@@ -35,7 +35,7 @@ import {
3535
getClosestInstanceFromNode,
3636
getEventListenerMap,
3737
} from '../client/ReactDOMComponentTree';
38-
import {unsafeCastDOMTopLevelTypeToString} from '../legacy-events/TopLevelEventTypes';
38+
import {unsafeCastDOMTopLevelTypeToString} from '../events/TopLevelEventTypes';
3939
import {HostRoot, SuspenseComponent} from 'react-reconciler/src/ReactWorkTags';
4040

4141
let attemptSynchronousHydration: (fiber: Object) => void;

packages/react-dom/src/legacy-events/ReactSyntheticEventType.js packages/react-dom/src/events/ReactSyntheticEventType.js

-6
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ export type CustomDispatchConfig = {|
3333

3434
export type ReactSyntheticEvent = {|
3535
dispatchConfig: DispatchConfig | CustomDispatchConfig,
36-
getPooled: (
37-
dispatchConfig: DispatchConfig | CustomDispatchConfig,
38-
targetInst: Fiber,
39-
nativeTarget: Event,
40-
nativeEventTarget: EventTarget,
41-
) => ReactSyntheticEvent,
4236
isPersistent: () => boolean,
4337
isPropagationStopped: () => boolean,
4438
_dispatchInstances?: null | Array<Fiber | null> | Fiber,

0 commit comments

Comments
 (0)