Skip to content

Commit e0ab1a4

Browse files
authored
ReactDOM.useEvent: enable on internal www and add inspection test (facebook#18395)
1 parent 6cceaeb commit e0ab1a4

File tree

6 files changed

+52
-5
lines changed

6 files changed

+52
-5
lines changed

Diff for: packages/react-debug-tools/src/__tests__/ReactHooksInspection-test.internal.js

+43
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@
1111
'use strict';
1212

1313
let React;
14+
let ReactDOM;
1415
let ReactDebugTools;
1516

1617
describe('ReactHooksInspection', () => {
1718
beforeEach(() => {
1819
jest.resetModules();
1920
const ReactFeatureFlags = require('shared/ReactFeatureFlags');
2021
ReactFeatureFlags.enableDeprecatedFlareAPI = true;
22+
ReactFeatureFlags.enableUseEventAPI = true;
2123
React = require('react');
24+
ReactDOM = require('react-dom');
2225
ReactDebugTools = require('react-debug-tools');
2326
});
2427

@@ -47,4 +50,44 @@ describe('ReactHooksInspection', () => {
4750
},
4851
]);
4952
});
53+
54+
it('should inspect a simple ReactDOM.useEvent hook', () => {
55+
let clickHandle;
56+
let ref;
57+
58+
const effect = () => {
59+
clickHandle.setListener(ref.current, () => {});
60+
};
61+
62+
function Foo(props) {
63+
ref = React.useRef(null);
64+
clickHandle = ReactDOM.unstable_useEvent('click');
65+
React.useEffect(effect);
66+
return <div ref={ref}>Hello world</div>;
67+
}
68+
let tree = ReactDebugTools.inspectHooks(Foo, {});
69+
expect(tree).toEqual([
70+
{
71+
isStateEditable: false,
72+
id: 0,
73+
name: 'Ref',
74+
subHooks: [],
75+
value: null,
76+
},
77+
{
78+
isStateEditable: false,
79+
id: 1,
80+
name: 'Event',
81+
value: {capture: false, passive: undefined, priority: 0, type: 'click'},
82+
subHooks: [],
83+
},
84+
{
85+
isStateEditable: false,
86+
id: 2,
87+
name: 'Effect',
88+
value: effect,
89+
subHooks: [],
90+
},
91+
]);
92+
});
5093
});

Diff for: packages/react-dom/src/client/ReactDOMComponent.js

+4
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,10 @@ export function listenToEventResponderEventTypes(
13481348
const targetEventType = isPassive
13491349
? eventType
13501350
: eventType.substring(0, eventType.length - 7);
1351+
// We don't listen to this as we actually emulate it in the host config
1352+
if (targetEventType === 'beforeblur') {
1353+
continue;
1354+
}
13511355
if (!listenerMap.has(eventKey)) {
13521356
if (isPassive) {
13531357
const activeKey = targetEventType + '_active';

Diff for: packages/react-dom/src/events/DOMModernPluginEventSystem.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,11 @@ export function isManagedDOMElement(
327327
export function isValidEventTarget(
328328
target: EventTarget | ReactScopeMethods,
329329
): boolean {
330-
return typeof (target: any).addEventListener === 'function';
330+
return typeof (target: Object).addEventListener === 'function';
331331
}
332332

333333
export function isReactScope(target: EventTarget | ReactScopeMethods): boolean {
334-
return typeof (target: any).getChildContextValues === 'function';
334+
return typeof (target: Object).getChildContextValues === 'function';
335335
}
336336

337337
export function dispatchEventForPluginEventSystem(

Diff for: packages/shared/forks/ReactFeatureFlags.test-renderer.www.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const disableInputAttributeSyncing = false;
2929
export const enableDeprecatedFlareAPI = true;
3030
export const enableFundamentalAPI = false;
3131
export const enableScopeAPI = true;
32-
export const enableUseEventAPI = false;
32+
export const enableUseEventAPI = true;
3333
export const warnAboutUnmockedScheduler = true;
3434
export const flushSuspenseFallbacksInTests = true;
3535
export const enableSuspenseCallback = true;

Diff for: packages/shared/forks/ReactFeatureFlags.testing.www.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const enableSchedulerDebugging = false;
2929
export const enableDeprecatedFlareAPI = true;
3030
export const enableFundamentalAPI = false;
3131
export const enableScopeAPI = true;
32-
export const enableUseEventAPI = false;
32+
export const enableUseEventAPI = true;
3333
export const warnAboutUnmockedScheduler = true;
3434
export const flushSuspenseFallbacksInTests = true;
3535
export const enableSuspenseCallback = true;

Diff for: packages/shared/forks/ReactFeatureFlags.www.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const enableFundamentalAPI = false;
8888

8989
export const enableScopeAPI = true;
9090

91-
export const enableUseEventAPI = false;
91+
export const enableUseEventAPI = true;
9292

9393
export const warnAboutUnmockedScheduler = true;
9494

0 commit comments

Comments
 (0)