Skip to content

Commit

Permalink
Bubble onSubmit/onReset behind a feature flag (#19333)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Jul 13, 2020
1 parent e2d73e9 commit 26472c8
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 5 deletions.
11 changes: 8 additions & 3 deletions packages/react-dom/src/__tests__/ReactDOMEventListener-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ describe('ReactDOMEventListener', () => {
// This is a special case for submit and reset events as they are listened on
// at the element level and not the document.
// @see https://github.com/facebook/react/pull/13462
it('should not receive submit events if native, interim DOM handler prevents it', () => {
it('should (or not) receive submit events if native, interim DOM handler prevents it', () => {
const container = document.createElement('div');
document.body.appendChild(container);

Expand Down Expand Up @@ -316,8 +316,13 @@ describe('ReactDOMEventListener', () => {
}),
);

expect(handleSubmit).toHaveBeenCalled();
expect(handleReset).toHaveBeenCalled();
if (gate(flags => flags.enableFormEventDelegation)) {
expect(handleSubmit).not.toHaveBeenCalled();
expect(handleReset).not.toHaveBeenCalled();
} else {
expect(handleSubmit).toHaveBeenCalled();
expect(handleReset).toHaveBeenCalled();
}
} finally {
document.body.removeChild(container);
}
Expand Down
8 changes: 6 additions & 2 deletions packages/react-dom/src/events/DOMModernPluginEventSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import getListener from './getListener';
import {passiveBrowserEventsSupported} from './checkPassiveEvents';

import {
enableFormEventDelegation,
enableLegacyFBSupport,
enableCreateEventHandleAPI,
enableScopeAPI,
Expand Down Expand Up @@ -222,8 +223,6 @@ export const capturePhaseEvents: Set<DOMTopLevelEventType> = new Set([
TOP_CANCEL,
TOP_CLOSE,
TOP_INVALID,
TOP_RESET,
TOP_SUBMIT,
TOP_ABORT,
TOP_CAN_PLAY,
TOP_CAN_PLAY_THROUGH,
Expand All @@ -249,6 +248,11 @@ export const capturePhaseEvents: Set<DOMTopLevelEventType> = new Set([
TOP_WAITING,
]);

if (!enableFormEventDelegation) {
capturePhaseEvents.add(TOP_SUBMIT);
capturePhaseEvents.add(TOP_RESET);
}

if (enableCreateEventHandleAPI) {
capturePhaseEvents.add(TOP_AFTER_BLUR);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ export const deferRenderPhaseUpdateToNextBatch = true;

// Replacement for runWithPriority in React internals.
export const decoupleUpdatePriorityFromScheduler = false;

// Enables delegation for submit and reset events.
export const enableFormEventDelegation = false;
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.native-fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const warnAboutSpreadingKeyToJSX = false;
export const enableComponentStackLocations = false;
export const enableLegacyFBSupport = false;
export const enableFilterEmptyStringAttributesDOM = false;
export const enableFormEventDelegation = false;

export const enableNewReconciler = false;
export const deferRenderPhaseUpdateToNextBatch = true;
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.native-oss.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const warnAboutSpreadingKeyToJSX = false;
export const enableComponentStackLocations = false;
export const enableLegacyFBSupport = false;
export const enableFilterEmptyStringAttributesDOM = false;
export const enableFormEventDelegation = false;

export const enableNewReconciler = false;
export const deferRenderPhaseUpdateToNextBatch = true;
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.test-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const warnAboutSpreadingKeyToJSX = false;
export const enableComponentStackLocations = true;
export const enableLegacyFBSupport = false;
export const enableFilterEmptyStringAttributesDOM = false;
export const enableFormEventDelegation = false;

export const enableNewReconciler = false;
export const deferRenderPhaseUpdateToNextBatch = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const warnAboutSpreadingKeyToJSX = false;
export const enableComponentStackLocations = true;
export const enableLegacyFBSupport = false;
export const enableFilterEmptyStringAttributesDOM = false;
export const enableFormEventDelegation = false;

export const enableNewReconciler = false;
export const deferRenderPhaseUpdateToNextBatch = true;
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const warnAboutSpreadingKeyToJSX = false;
export const enableComponentStackLocations = true;
export const enableLegacyFBSupport = false;
export const enableFilterEmptyStringAttributesDOM = false;
export const enableFormEventDelegation = false;

export const enableNewReconciler = false;
export const deferRenderPhaseUpdateToNextBatch = true;
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.testing.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const warnAboutSpreadingKeyToJSX = false;
export const enableComponentStackLocations = true;
export const enableLegacyFBSupport = !__EXPERIMENTAL__;
export const enableFilterEmptyStringAttributesDOM = false;
export const enableFormEventDelegation = false;

export const enableNewReconciler = false;
export const deferRenderPhaseUpdateToNextBatch = true;
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.www-dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
// to __VARIANT__.
export const enableTrustedTypesIntegration = false;
export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;

export const enableFormEventDelegation = __VARIANT__;
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const {
decoupleUpdatePriorityFromScheduler,
enableDebugTracing,
enableSchedulingProfiler,
enableFormEventDelegation,
} = dynamicFeatureFlags;

// On WWW, __EXPERIMENTAL__ is used for a new modern build.
Expand Down

0 comments on commit 26472c8

Please sign in to comment.