Skip to content

Commit

Permalink
Modern Event System: make on*Capture events use capture phase
Browse files Browse the repository at this point in the history
WIP

WIP

FIX

FIX

Fix

WIP

Virtualize plugins

Fix lint

Clear up conflict

Clearn things up

Fix logic for plugins

Fix test

Simplify logic

Simplify logic
  • Loading branch information
trueadm committed Jul 6, 2020
1 parent c3e42a9 commit f888b6c
Show file tree
Hide file tree
Showing 12 changed files with 337 additions and 168 deletions.
11 changes: 3 additions & 8 deletions packages/react-dom/src/__tests__/ReactDOMComponent-test.js
Expand Up @@ -2714,28 +2714,23 @@ describe('ReactDOMComponent', () => {

innerRef.current.click();

// The order we receive here is not ideal since it is expected that the
// capture listener fire before all bubble listeners. Other React apps
// might depend on this.
//
// @see https://github.com/facebook/react/pull/12919#issuecomment-395224674
if (ReactFeatureFlags.enableLegacyFBSupport) {
// The order will change here, as the legacy FB support adds
// the event listener onto the document after the one above has.
expect(eventOrder).toEqual([
'document capture',
'document bubble',
'outer capture',
'inner capture',
'document bubble',
'inner bubble',
'outer capture',
'outer bubble',
]);
} else {
expect(eventOrder).toEqual([
'document capture',
'outer capture',
'inner capture',
'inner bubble',
'outer capture',
'outer bubble',
'document bubble',
]);
Expand Down
1 change: 1 addition & 0 deletions packages/react-dom/src/client/ReactDOMComponent.js
Expand Up @@ -13,6 +13,7 @@ import {
registrationNameDependencies,
possibleRegistrationNames,
} from '../events/EventRegistry';

import {canUseDOM} from 'shared/ExecutionEnvironment';
import invariant from 'shared/invariant';
import {
Expand Down
5 changes: 3 additions & 2 deletions packages/react-dom/src/client/ReactDOMEventHandle.js
Expand Up @@ -26,7 +26,6 @@ import {ELEMENT_NODE} from '../shared/HTMLNodeType';
import {
listenToTopLevelEvent,
addEventTypeToDispatchConfig,
capturePhaseEvents,
} from '../events/DOMModernPluginEventSystem';

import {HostRoot, HostPortal} from 'react-reconciler/src/ReactWorkTags';
Expand Down Expand Up @@ -87,6 +86,7 @@ function registerEventOnNearestTargetContainer(
topLevelType: DOMTopLevelEventType,
passive: boolean | void,
priority: EventPriority | void,
capture: boolean,
): void {
// If it is, find the nearest root or portal and make it
// our event handle target container.
Expand All @@ -99,7 +99,6 @@ function registerEventOnNearestTargetContainer(
);
}
const listenerMap = getEventListenerMap(targetContainer);
const capture = capturePhaseEvents.has(topLevelType);
listenToTopLevelEvent(
topLevelType,
targetContainer,
Expand Down Expand Up @@ -182,6 +181,7 @@ export function createEventHandle(
topLevelType,
passive,
priority,
capture,
);
} else if (enableScopeAPI && isReactScope(target)) {
const scopeTarget = ((target: any): ReactScopeInstance);
Expand All @@ -195,6 +195,7 @@ export function createEventHandle(
topLevelType,
passive,
priority,
capture,
);
} else if (isValidEventTarget(target)) {
const eventTarget = ((target: any): EventTarget);
Expand Down

0 comments on commit f888b6c

Please sign in to comment.