Skip to content

Commit 4cc5b7a

Browse files
authored
Add support for event information in React scheduler tracks in React Native (facebook#35947)
## Summary This defines the same fiber configuration for RN as used in DOM, so we can expose event timing information in the React scheduler tracks in performance traces. This was unblocked by facebook#35913 and facebook#35912. ## How did you test this change? Manually compiled the renderer and tested e2e in FB infra: <img width="1217" height="161" alt="Screenshot 2026-03-03 at 10 10 44" src="https://github.com/user-attachments/assets/6ca1512e-dcaf-49cf-8da9-1c6ae554733a" />
1 parent aac12ce commit 4cc5b7a

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

packages/react-native-renderer/src/ReactFiberConfigFabric.js

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,14 +422,48 @@ export function resolveUpdatePriority(): EventPriority {
422422
return DefaultEventPriority;
423423
}
424424

425-
export function trackSchedulerEvent(): void {}
425+
let schedulerEvent: void | Event = undefined;
426+
export function trackSchedulerEvent(): void {
427+
schedulerEvent = global.event;
428+
}
429+
430+
function getEventType(event: Event): null | string {
431+
if (event.type) {
432+
return event.type;
433+
}
434+
435+
// Legacy implementation. RN does not define the `type` property on the event object yet.
436+
// $FlowExpectedError[prop-missing]
437+
const dispatchConfig = event.dispatchConfig;
438+
if (
439+
dispatchConfig == null ||
440+
dispatchConfig.phasedRegistrationNames == null
441+
) {
442+
return null;
443+
}
444+
445+
const rawEventType =
446+
dispatchConfig.phasedRegistrationNames.bubbled ||
447+
dispatchConfig.phasedRegistrationNames.captured;
448+
if (!rawEventType) {
449+
return null;
450+
}
451+
452+
if (rawEventType.startsWith('on')) {
453+
return rawEventType.slice(2).toLowerCase();
454+
}
455+
456+
return rawEventType.toLowerCase();
457+
}
426458

427459
export function resolveEventType(): null | string {
428-
return null;
460+
const event = global.event;
461+
return event && event !== schedulerEvent ? getEventType(event) : null;
429462
}
430463

431464
export function resolveEventTimeStamp(): number {
432-
return -1.1;
465+
const event = global.event;
466+
return event && event !== schedulerEvent ? event.timeStamp : -1.1;
433467
}
434468

435469
export function shouldAttemptEagerTransition(): boolean {

0 commit comments

Comments
 (0)