Rename "tracking" API to "tracing" (#13641)

* Replaced "tracking" with "tracing" in all directory and file names
* Global rename of track/tracking/tracked to trace/tracing/traced
This commit is contained in:
Brian Vaughn authored and GitHub committed 2018-09-13 14:23:16 -07:00
1 parent 9a6c5ba72d
commit 4bcee56210
43 files changed
+889 -910

No files matched your search

@@ -2,7 +2,7 @@
<html style="width: 100%; height: 100%;">
<head>
<meta charset="utf-8">
<title>Test tracking UMD</title>
<title>Test tracing UMD</title>
<style>
body {
font-family: sans-serif;
@@ -36,9 +36,9 @@
</style>
</head>
<body>
<h1>Test tracking UMD</h1>
<h1>Test tracing UMD</h1>
<p>
This fixture tests that the new tracking API is accessible via UMD build using the UMD shim.
This fixture tests that the new tracing API is accessible via UMD build using the UMD shim.
It does not exhaustively test API functionality, only that the forwarded methods can be called.
</p>
<p>
@@ -52,19 +52,19 @@
<li id="checkSchedulerAPI" data-value="...">
<strong>Test scheduler API</strong>
</li>
<li id="checkSchedulerTrackingAPI" data-value="...">
<strong>Test tracking API</strong>
<li id="checkSchedulerTracingAPI" data-value="...">
<strong>Test tracing API</strong>
</li>
<li id="checkSchedulerTrackingSubscriptionsAPI" data-value="...">
<strong>Test tracking subscriptions API</strong>
<li id="checkSchedulerTracingSubscriptionsAPI" data-value="...">
<strong>Test tracing subscriptions API</strong>
</li>
<li id="checkEndToEndIntegration" data-value="...">
<strong>Test end-to-end integration</strong>
</li>
</ol>
<!-- Load the tracking API before react to test that it's lazily evaluated -->
<!-- Load the tracing API before react to test that it's lazily evaluated -->
<script src="../../build/node_modules/schedule/umd/schedule.development.js"></script>
<script src="../../build/node_modules/schedule/umd/schedule-tracking.development.js"></script>
<script src="../../build/node_modules/schedule/umd/schedule-tracing.development.js"></script>
<script src="../../build/node_modules/react/umd/react.development.js"></script>
<script src="../../build/node_modules/react-dom/umd/react-dom.development.js"></script>
<script src="./script.js"></script>
@@ -14,10 +14,10 @@ function runAllTests() {
checkSchedulerAPI();
} finally {
try {
checkSchedulerTrackingAPI();
checkSchedulerTracingAPI();
} finally {
try {
checkSchedulerTrackingSubscriptionsAPI();
checkSchedulerTracingSubscriptionsAPI();
} finally {
checkEndToEndIntegration();
}
@@ -44,23 +44,23 @@ function checkSchedulerAPI() {
});
}
function checkSchedulerTrackingAPI() {
runTest(document.getElementById('checkSchedulerTrackingAPI'), () => {
function checkSchedulerTracingAPI() {
runTest(document.getElementById('checkSchedulerTracingAPI'), () => {
if (
typeof ScheduleTracking === 'undefined' ||
typeof ScheduleTracking.unstable_clear !== 'function' ||
typeof ScheduleTracking.unstable_getCurrent !== 'function' ||
typeof ScheduleTracking.unstable_getThreadID !== 'function' ||
typeof ScheduleTracking.unstable_track !== 'function' ||
typeof ScheduleTracking.unstable_wrap !== 'function'
typeof ScheduleTracing === 'undefined' ||
typeof ScheduleTracing.unstable_clear !== 'function' ||
typeof ScheduleTracing.unstable_getCurrent !== 'function' ||
typeof ScheduleTracing.unstable_getThreadID !== 'function' ||
typeof ScheduleTracing.unstable_trace !== 'function' ||
typeof ScheduleTracing.unstable_wrap !== 'function'
) {
throw 'API is not defined';
}
try {
let interactionsSet;
ScheduleTracking.unstable_track('test', 123, () => {
interactionsSet = ScheduleTracking.unstable_getCurrent();
ScheduleTracing.unstable_trace('test', 123, () => {
interactionsSet = ScheduleTracing.unstable_getCurrent();
});
if (interactionsSet.size !== 1) {
throw null;
@@ -73,32 +73,32 @@ function checkSchedulerTrackingAPI() {
throw 'API does not work';
}
const ForwardedSchedulerTracking =
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking;
const ForwardedSchedulerTracing =
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing;
if (
ScheduleTracking.unstable_getThreadID() ===
ForwardedSchedulerTracking.unstable_getThreadID()
ScheduleTracing.unstable_getThreadID() ===
ForwardedSchedulerTracing.unstable_getThreadID()
) {
throw 'API forwarding is broken';
}
});
}
function checkSchedulerTrackingSubscriptionsAPI() {
function checkSchedulerTracingSubscriptionsAPI() {
runTest(
document.getElementById('checkSchedulerTrackingSubscriptionsAPI'),
document.getElementById('checkSchedulerTracingSubscriptionsAPI'),
() => {
if (
typeof ScheduleTracking === 'undefined' ||
typeof ScheduleTracking.unstable_subscribe !== 'function' ||
typeof ScheduleTracking.unstable_unsubscribe !== 'function'
typeof ScheduleTracing === 'undefined' ||
typeof ScheduleTracing.unstable_subscribe !== 'function' ||
typeof ScheduleTracing.unstable_unsubscribe !== 'function'
) {
throw 'API is not defined';
}
const onInteractionScheduledWorkCompletedCalls = [];
const onInteractionTrackedCalls = [];
const onInteractionTracedCalls = [];
const onWorkCanceledCalls = [];
const onWorkScheduledCalls = [];
const onWorkStartedCalls = [];
@@ -106,7 +106,7 @@ function checkSchedulerTrackingSubscriptionsAPI() {
const subscriber = {
onInteractionScheduledWorkCompleted: (...args) =>
onInteractionScheduledWorkCompletedCalls.push(args),
onInteractionTracked: (...args) => onInteractionTrackedCalls.push(args),
onInteractionTraced: (...args) => onInteractionTracedCalls.push(args),
onWorkCanceled: (...args) => onWorkCanceledCalls.push(args),
onWorkScheduled: (...args) => onWorkScheduledCalls.push(args),
onWorkStarted: (...args) => onWorkStartedCalls.push(args),
@@ -114,38 +114,38 @@ function checkSchedulerTrackingSubscriptionsAPI() {
};
try {
ScheduleTracking.unstable_subscribe(subscriber);
ScheduleTracking.unstable_track('foo', 123, () => {});
ScheduleTracking.unstable_unsubscribe(subscriber);
if (onInteractionTrackedCalls.length !== 1) {
ScheduleTracing.unstable_subscribe(subscriber);
ScheduleTracing.unstable_trace('foo', 123, () => {});
ScheduleTracing.unstable_unsubscribe(subscriber);
if (onInteractionTracedCalls.length !== 1) {
throw null;
}
const interaction = onInteractionTrackedCalls[0][0];
const interaction = onInteractionTracedCalls[0][0];
if (interaction.name !== 'foo' || interaction.timestamp !== 123) {
throw null;
}
ScheduleTracking.unstable_track('bar', 456, () => {});
if (onInteractionTrackedCalls.length !== 1) {
ScheduleTracing.unstable_trace('bar', 456, () => {});
if (onInteractionTracedCalls.length !== 1) {
throw null;
}
} catch (error) {
throw 'API does not forward methods';
}
const ForwardedSchedulerTracking =
const ForwardedSchedulerTracing =
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
.ScheduleTracking;
.ScheduleTracing;
try {
ForwardedSchedulerTracking.unstable_subscribe(subscriber);
ScheduleTracking.unstable_track('foo', 123, () => {});
ForwardedSchedulerTracking.unstable_track('bar', 456, () => {});
ScheduleTracking.unstable_unsubscribe(subscriber);
if (onInteractionTrackedCalls.length !== 3) {
ForwardedSchedulerTracing.unstable_subscribe(subscriber);
ScheduleTracing.unstable_trace('foo', 123, () => {});
ForwardedSchedulerTracing.unstable_trace('bar', 456, () => {});
ScheduleTracing.unstable_unsubscribe(subscriber);
if (onInteractionTracedCalls.length !== 3) {
throw null;
}
const interactionFoo = onInteractionTrackedCalls[1][0];
const interactionBar = onInteractionTrackedCalls[2][0];
const interactionFoo = onInteractionTracedCalls[1][0];
const interactionBar = onInteractionTracedCalls[2][0];
if (
interactionFoo.name !== 'foo' ||
interactionFoo.timestamp !== 123 ||
@@ -154,8 +154,8 @@ function checkSchedulerTrackingSubscriptionsAPI() {
) {
throw null;
}
ForwardedSchedulerTracking.unstable_track('baz', 789, () => {});
if (onInteractionTrackedCalls.length !== 3) {
ForwardedSchedulerTracing.unstable_trace('baz', 789, () => {});
if (onInteractionTracedCalls.length !== 3) {
throw null;
}
} catch (error) {
@@ -172,7 +172,7 @@ function checkEndToEndIntegration() {
const onRender = (...args) => onRenderCalls.push(args);
const container = document.createElement('div');
ScheduleTracking.unstable_track('render', 123, () => {
ScheduleTracing.unstable_trace('render', 123, () => {
ReactDOM.render(
React.createElement(
React.unstable_Profiler,
@@ -1,9 +1,6 @@
import React, {Placeholder, PureComponent} from 'react';
import {unstable_scheduleWork} from 'schedule';
import {
unstable_track as track,
unstable_wrap as wrap,
} from 'schedule/tracking';
import {unstable_trace as trace, unstable_wrap as wrap} from 'schedule/tracing';
import {createResource} from 'simple-cache-provider';
import {cache} from '../cache';
import Spinner from './Spinner';
@@ -32,15 +29,15 @@ export default class App extends PureComponent {
}
handleUserClick = id => {
track(`View ${id}`, performance.now(), () => {
track(`View ${id} (high-pri)`, performance.now(), () =>
trace(`View ${id}`, performance.now(), () => {
trace(`View ${id} (high-pri)`, performance.now(), () =>
this.setState({
currentId: id,
})
);
unstable_scheduleWork(
wrap(() =>
track(`View ${id} (low-pri)`, performance.now(), () =>
trace(`View ${id} (low-pri)`, performance.now(), () =>
this.setState({
showDetail: true,
})
@@ -51,7 +48,7 @@ export default class App extends PureComponent {
};
handleBackClick = () =>
track('View list', performance.now(), () =>
trace('View list', performance.now(), () =>
this.setState({
currentId: null,
showDetail: false,
@@ -1,6 +1,6 @@
import React, {Fragment, PureComponent} from 'react';
import {unstable_createRoot, render} from 'react-dom';
import {unstable_track as track} from 'schedule/tracking';
import {unstable_trace as trace} from 'schedule/tracing';
import {cache} from './cache';
import {
setFakeRequestTime,
@@ -65,7 +65,7 @@ class Debugger extends PureComponent {
}
handleReset = () => {
track('Clear cache', () => {
trace('Clear cache', () => {
cache.invalidate();
this.setState(state => ({
requests: {},
+2 -2
View File
@@ -20,7 +20,7 @@ import type {ExpirationTime} from './ReactFiberExpirationTime';
import type {CapturedValue, CapturedError} from './ReactCapturedValue';
import {
enableSchedulerTracking,
enableSchedulerTracing,
enableProfilerTimer,
enableSuspense,
} from 'shared/ReactFeatureFlags';
@@ -329,7 +329,7 @@ function commitLifeCycles(
if (enableProfilerTimer) {
const onRender = finishedWork.memoizedProps.onRender;
if (enableSchedulerTracking) {
if (enableSchedulerTracing) {
onRender(
finishedWork.memoizedProps.id,
current === null ? 'mount' : 'update',
+10 -10
View File
@@ -10,13 +10,13 @@
import type {Fiber} from './ReactFiber';
import type {ExpirationTime} from './ReactFiberExpirationTime';
import type {TimeoutHandle, NoTimeout} from './ReactFiberHostConfig';
import type {Interaction} from 'schedule/src/Tracking';
import type {Interaction} from 'schedule/src/Tracing';
import {noTimeout} from './ReactFiberHostConfig';
import {createHostRootFiber} from './ReactFiber';
import {NoWork} from './ReactFiberExpirationTime';
import {enableSchedulerTracking} from 'shared/ReactFeatureFlags';
import {unstable_getThreadID} from 'schedule/tracking';
import {enableSchedulerTracing} from 'shared/ReactFeatureFlags';
import {unstable_getThreadID} from 'schedule/tracing';
/* eslint-disable no-use-before-define */
// TODO: This should be lifted into the renderer.
@@ -80,10 +80,10 @@ type BaseFiberRootProperties = {|
nextScheduledRoot: FiberRoot | null,
|};
// The following attributes are only used by interaction tracking builds.
// The following attributes are only used by interaction tracing builds.
// They enable interactions to be associated with their async work,
// And expose interaction metadata to the React DevTools Profiler plugin.
// Note that these attributes are only defined when the enableSchedulerTracking flag is enabled.
// Note that these attributes are only defined when the enableSchedulerTracing flag is enabled.
type ProfilingOnlyFiberRootProperties = {|
interactionThreadID: number,
memoizedInteractions: Set<Interaction>,
@@ -92,9 +92,9 @@ type ProfilingOnlyFiberRootProperties = {|
// Exported FiberRoot type includes all properties,
// To avoid requiring potentially error-prone :any casts throughout the project.
// Profiling properties are only safe to access in profiling builds (when enableSchedulerTracking is true).
// Profiling properties are only safe to access in profiling builds (when enableSchedulerTracing is true).
// The types are defined separately within this file to ensure they stay in sync.
// (We don't have to use an inline :any cast when enableSchedulerTracking is disabled.)
// (We don't have to use an inline :any cast when enableSchedulerTracing is disabled.)
export type FiberRoot = {
...BaseFiberRootProperties,
...ProfilingOnlyFiberRootProperties,
@@ -111,7 +111,7 @@ export function createFiberRoot(
const uninitializedFiber = createHostRootFiber(isAsync);
let root;
if (enableSchedulerTracking) {
if (enableSchedulerTracing) {
root = ({
current: uninitializedFiber,
containerInfo: containerInfo,
@@ -170,8 +170,8 @@ export function createFiberRoot(
uninitializedFiber.stateNode = root;
// The reason for the way the Flow types are structured in this file,
// Is to avoid needing :any casts everywhere interaction tracking fields are used.
// Unfortunately that requires an :any cast for non-interaction tracking capable builds.
// Is to avoid needing :any casts everywhere interaction tracing fields are used.
// Unfortunately that requires an :any cast for non-interaction tracing capable builds.
// $FlowFixMe Remove this :any cast and replace it with something better.
return ((root: any): FiberRoot);
}
+19 -19
View File
@@ -10,9 +10,9 @@
import type {Fiber} from './ReactFiber';
import type {Batch, FiberRoot} from './ReactFiberRoot';
import type {ExpirationTime} from './ReactFiberExpirationTime';
import type {Interaction} from 'schedule/src/Tracking';
import type {Interaction} from 'schedule/src/Tracing';
import {__interactionsRef, __subscriberRef} from 'schedule/tracking';
import {__interactionsRef, __subscriberRef} from 'schedule/tracing';
import {
invokeGuardedCallback,
hasCaughtError,
@@ -44,7 +44,7 @@ import {
HostPortal,
} from 'shared/ReactWorkTags';
import {
enableSchedulerTracking,
enableSchedulerTracing,
enableProfilerTimer,
enableUserTimingAPI,
replayFailedUnitOfWorkWithInvokeGuardedCallback,
@@ -168,13 +168,13 @@ let didWarnSetStateChildContext;
let warnAboutUpdateOnUnmounted;
let warnAboutInvalidUpdates;
if (enableSchedulerTracking) {
if (enableSchedulerTracing) {
// Provide explicit error message when production+profiling bundle of e.g. react-dom
// is used with production (non-profiling) bundle of schedule/tracking
// is used with production (non-profiling) bundle of schedule/tracing
invariant(
__interactionsRef != null && __interactionsRef.current != null,
'It is not supported to run the profiling version of a renderer (for example, `react-dom/profiling`) ' +
'without also replacing the `schedule/tracking` module with `schedule/tracking-profiling`. ' +
'without also replacing the `schedule/tracing` module with `schedule/tracing-profiling`. ' +
'Your bundler might have a setting for aliasing both modules. ' +
'Learn more at http://fb.me/react-profiling',
);
@@ -566,10 +566,10 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void {
markCommittedPriorityLevels(root, earliestRemainingTimeBeforeCommit);
let prevInteractions: Set<Interaction> = (null: any);
let committedInteractions: Array<Interaction> = enableSchedulerTracking
let committedInteractions: Array<Interaction> = enableSchedulerTracing
? []
: (null: any);
if (enableSchedulerTracking) {
if (enableSchedulerTracing) {
// Restore any pending interactions at this point,
// So that cascading work triggered during the render phase will be accounted for.
prevInteractions = __interactionsRef.current;
@@ -767,7 +767,7 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void {
}
onCommit(root, earliestRemainingTimeAfterCommit);
if (enableSchedulerTracking) {
if (enableSchedulerTracing) {
__interactionsRef.current = prevInteractions;
let subscriber;
@@ -1175,8 +1175,8 @@ function renderRoot(
const expirationTime = root.nextExpirationTimeToWorkOn;
let prevInteractions: Set<Interaction> = (null: any);
if (enableSchedulerTracking) {
// We're about to start new tracked work.
if (enableSchedulerTracing) {
// We're about to start new traced work.
// Restore pending interactions so cascading work triggered during the render phase will be accounted for.
prevInteractions = __interactionsRef.current;
__interactionsRef.current = root.memoizedInteractions;
@@ -1200,7 +1200,7 @@ function renderRoot(
);
root.pendingCommitExpirationTime = NoWork;
if (enableSchedulerTracking) {
if (enableSchedulerTracing) {
// Determine which interactions this batch of work currently includes,
// So that we can accurately attribute time spent working on it,
// And so that cascading work triggered during the render phase will be associated with it.
@@ -1231,7 +1231,7 @@ function renderRoot(
try {
subscriber.onWorkStarted(interactions, threadID);
} catch (error) {
// Work thrown by an interaction tracking subscriber should be rethrown,
// Work thrown by an interaction tracing subscriber should be rethrown,
// But only once it's safe (to avoid leaveing the scheduler in an invalid state).
// Store the error for now and we'll re-throw in finishRendering().
if (!hasUnhandledError) {
@@ -1305,8 +1305,8 @@ function renderRoot(
break;
} while (true);
if (enableSchedulerTracking) {
// Tracked work is done for now; restore the previous interactions.
if (enableSchedulerTracing) {
// Traced work is done for now; restore the previous interactions.
__interactionsRef.current = prevInteractions;
}
@@ -1614,7 +1614,7 @@ function retrySuspendedRoot(
scheduleWorkToRoot(fiber, retryTime);
const rootExpirationTime = root.expirationTime;
if (rootExpirationTime !== NoWork) {
if (enableSchedulerTracking) {
if (enableSchedulerTracing) {
// Restore previous interactions so that new work is associated with them.
let prevInteractions = __interactionsRef.current;
__interactionsRef.current = root.memoizedInteractions;
@@ -1685,7 +1685,7 @@ function storeInteractionsForExpirationTime(
expirationTime: ExpirationTime,
updateInteractionCounts: boolean,
): void {
if (!enableSchedulerTracking) {
if (!enableSchedulerTracing) {
return;
}
@@ -1744,7 +1744,7 @@ function scheduleWork(fiber: Fiber, expirationTime: ExpirationTime) {
return;
}
if (enableSchedulerTracking) {
if (enableSchedulerTracing) {
storeInteractionsForExpirationTime(root, expirationTime, true);
}
@@ -1935,7 +1935,7 @@ function onTimeout(root, finishedWork, suspendedExpirationTime) {
recomputeCurrentRendererTime();
currentSchedulerTime = currentRendererTime;
if (enableSchedulerTracking) {
if (enableSchedulerTracing) {
// Don't update pending interaction counts for suspense timeouts,
// Because we know we still need to do more work in this case.
suspenseDidTimeout = true;
@@ -10,16 +10,16 @@
'use strict';
describe('ReactTracking', () => {
it('should error if profiling renderer and non-profiling schedule/tracking bundles are combined', () => {
describe('ReactTracing', () => {
it('should error if profiling renderer and non-profiling schedule/tracing bundles are combined', () => {
jest.resetModules();
const ReactFeatureFlags = require('shared/ReactFeatureFlags');
ReactFeatureFlags.enableSchedulerTracking = false;
ReactFeatureFlags.enableSchedulerTracing = false;
require('schedule/tracking');
require('schedule/tracing');
ReactFeatureFlags.enableSchedulerTracking = true;
ReactFeatureFlags.enableSchedulerTracing = true;
expect(() => require('react-dom')).toThrow(
'Learn more at http://fb.me/react-profiling',
+4 -4
View File
@@ -18,10 +18,10 @@ import {
unstable_getCurrent,
unstable_getThreadID,
unstable_subscribe,
unstable_track,
unstable_trace,
unstable_unsubscribe,
unstable_wrap,
} from 'schedule/tracking';
} from 'schedule/tracing';
import ReactCurrentOwner from './ReactCurrentOwner';
import ReactDebugCurrentFrame from './ReactDebugCurrentFrame';
@@ -43,14 +43,14 @@ if (__UMD__) {
unstable_now,
unstable_scheduleWork,
},
ScheduleTracking: {
ScheduleTracing: {
__interactionsRef,
__subscriberRef,
unstable_clear,
unstable_getCurrent,
unstable_getThreadID,
unstable_subscribe,
unstable_track,
unstable_trace,
unstable_unsubscribe,
unstable_wrap,
},
@@ -15,14 +15,14 @@ let ReactFeatureFlags;
let ReactNoop;
let ReactTestRenderer;
let advanceTimeBy;
let SchedulerTracking;
let SchedulerTracing;
let mockNow;
let AdvanceTime;
function loadModules({
enableProfilerTimer = true,
enableSuspense = false,
enableSchedulerTracking = true,
enableSchedulerTracing = true,
replayFailedUnitOfWorkWithInvokeGuardedCallback = false,
useNoopRenderer = false,
} = {}) {
@@ -37,12 +37,12 @@ function loadModules({
ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
ReactFeatureFlags.enableProfilerTimer = enableProfilerTimer;
ReactFeatureFlags.enableGetDerivedStateFromCatch = true;
ReactFeatureFlags.enableSchedulerTracking = enableSchedulerTracking;
ReactFeatureFlags.enableSchedulerTracing = enableSchedulerTracing;
ReactFeatureFlags.enableSuspense = enableSuspense;
ReactFeatureFlags.replayFailedUnitOfWorkWithInvokeGuardedCallback = replayFailedUnitOfWorkWithInvokeGuardedCallback;
React = require('react');
SchedulerTracking = require('schedule/tracking');
SchedulerTracing = require('schedule/tracing');
if (useNoopRenderer) {
ReactNoop = require('react-noop-renderer');
@@ -82,17 +82,17 @@ const mockDevToolsForTest = () => {
describe('Profiler', () => {
describe('works in profiling and non-profiling bundles', () => {
[true, false].forEach(enableSchedulerTracking => {
[true, false].forEach(enableSchedulerTracing => {
[true, false].forEach(enableProfilerTimer => {
describe(`enableSchedulerTracking:${
enableSchedulerTracking ? 'enabled' : 'disabled'
describe(`enableSchedulerTracing:${
enableSchedulerTracing ? 'enabled' : 'disabled'
} enableProfilerTimer:${
enableProfilerTimer ? 'enabled' : 'disabled'
}`, () => {
beforeEach(() => {
jest.resetModules();
loadModules({enableSchedulerTracking, enableProfilerTimer});
loadModules({enableSchedulerTracing, enableProfilerTimer});
});
// This will throw in production too,
@@ -165,12 +165,12 @@ describe('Profiler', () => {
});
});
[true, false].forEach(enableSchedulerTracking => {
[true, false].forEach(enableSchedulerTracing => {
describe('onRender callback', () => {
beforeEach(() => {
jest.resetModules();
loadModules({enableSchedulerTracking});
loadModules({enableSchedulerTracing});
});
it('should handle errors thrown', () => {
@@ -265,16 +265,14 @@ describe('Profiler', () => {
let [call] = callback.mock.calls;
expect(call).toHaveLength(enableSchedulerTracking ? 7 : 6);
expect(call).toHaveLength(enableSchedulerTracing ? 7 : 6);
expect(call[0]).toBe('test');
expect(call[1]).toBe('mount');
expect(call[2]).toBe(10); // actual time
expect(call[3]).toBe(10); // base time
expect(call[4]).toBe(5); // start time
expect(call[5]).toBe(15); // commit time
expect(call[6]).toEqual(
enableSchedulerTracking ? new Set() : undefined,
); // interaction events
expect(call[6]).toEqual(enableSchedulerTracing ? new Set() : undefined); // interaction events
callback.mockReset();
@@ -290,16 +288,14 @@ describe('Profiler', () => {
[call] = callback.mock.calls;
expect(call).toHaveLength(enableSchedulerTracking ? 7 : 6);
expect(call).toHaveLength(enableSchedulerTracing ? 7 : 6);
expect(call[0]).toBe('test');
expect(call[1]).toBe('update');
expect(call[2]).toBe(10); // actual time
expect(call[3]).toBe(10); // base time
expect(call[4]).toBe(35); // start time
expect(call[5]).toBe(45); // commit time
expect(call[6]).toEqual(
enableSchedulerTracking ? new Set() : undefined,
); // interaction events
expect(call[6]).toEqual(enableSchedulerTracing ? new Set() : undefined); // interaction events
callback.mockReset();
@@ -315,16 +311,14 @@ describe('Profiler', () => {
[call] = callback.mock.calls;
expect(call).toHaveLength(enableSchedulerTracking ? 7 : 6);
expect(call).toHaveLength(enableSchedulerTracing ? 7 : 6);
expect(call[0]).toBe('test');
expect(call[1]).toBe('update');
expect(call[2]).toBe(4); // actual time
expect(call[3]).toBe(4); // base time
expect(call[4]).toBe(65); // start time
expect(call[5]).toBe(69); // commit time
expect(call[6]).toEqual(
enableSchedulerTracking ? new Set() : undefined,
); // interaction events
expect(call[6]).toEqual(enableSchedulerTracing ? new Set() : undefined); // interaction events
});
it('includes render times of nested Profilers in their parent times', () => {
@@ -362,7 +356,7 @@ describe('Profiler', () => {
expect(parentCall[5]).toBe(35); // commit time
});
it('tracks sibling Profilers separately', () => {
it('traces sibling Profilers separately', () => {
const callback = jest.fn();
advanceTimeBy(5); // 0 -> 5
@@ -1220,9 +1214,9 @@ describe('Profiler', () => {
expect(ReactNoop.getRoot('two').current.actualDuration).toBe(14);
});
describe('interaction tracking', () => {
describe('interaction tracing', () => {
let onInteractionScheduledWorkCompleted;
let onInteractionTracked;
let onInteractionTraced;
let onWorkCanceled;
let onWorkScheduled;
let onWorkStarted;
@@ -1239,7 +1233,7 @@ describe('Profiler', () => {
jest.resetModules();
loadModules({
enableSchedulerTracking: true,
enableSchedulerTracing: true,
});
throwInOnInteractionScheduledWorkCompleted = false;
@@ -1252,7 +1246,7 @@ describe('Profiler', () => {
throw Error('Expected error onInteractionScheduledWorkCompleted');
}
});
onInteractionTracked = jest.fn();
onInteractionTraced = jest.fn();
onWorkCanceled = jest.fn();
onWorkScheduled = jest.fn(() => {
if (throwInOnWorkScheduled) {
@@ -1271,9 +1265,9 @@ describe('Profiler', () => {
});
// Verify interaction subscriber methods are called as expected.
SchedulerTracking.unstable_subscribe({
SchedulerTracing.unstable_subscribe({
onInteractionScheduledWorkCompleted,
onInteractionTracked,
onInteractionTraced,
onWorkCanceled,
onWorkScheduled,
onWorkStarted,
@@ -1293,7 +1287,7 @@ describe('Profiler', () => {
// Errors that happen inside of a subscriber should throw,
throwInOnWorkScheduled = true;
expect(() => {
SchedulerTracking.unstable_track('event', mockNow(), () => {
SchedulerTracing.unstable_trace('event', mockNow(), () => {
renderer = ReactTestRenderer.create(<Component>fail</Component>, {
unstable_isAsync: true,
});
@@ -1319,7 +1313,7 @@ describe('Profiler', () => {
}
let renderer;
SchedulerTracking.unstable_track('event', mockNow(), () => {
SchedulerTracing.unstable_trace('event', mockNow(), () => {
renderer = ReactTestRenderer.create(<Component>text</Component>, {
unstable_isAsync: true,
});
@@ -1348,7 +1342,7 @@ describe('Profiler', () => {
}
let renderer;
SchedulerTracking.unstable_track('event', mockNow(), () => {
SchedulerTracing.unstable_trace('event', mockNow(), () => {
renderer = ReactTestRenderer.create(<Component>text</Component>, {
unstable_isAsync: true,
});
@@ -1390,8 +1384,8 @@ describe('Profiler', () => {
};
let renderer;
SchedulerTracking.unstable_track(eventOne.name, mockNow(), () => {
SchedulerTracking.unstable_track(eventTwo.name, mockNow(), () => {
SchedulerTracing.unstable_trace(eventOne.name, mockNow(), () => {
SchedulerTracing.unstable_trace(eventTwo.name, mockNow(), () => {
renderer = ReactTestRenderer.create(<Component>text</Component>, {
unstable_isAsync: true,
});
@@ -1410,7 +1404,7 @@ describe('Profiler', () => {
});
});
it('should associate tracked events with their subsequent commits', () => {
it('should associate traced events with their subsequent commits', () => {
let instance = null;
const Yield = ({duration = 10, value}) => {
@@ -1445,7 +1439,7 @@ describe('Profiler', () => {
const onRender = jest.fn();
let renderer;
SchedulerTracking.unstable_track(
SchedulerTracing.unstable_trace(
interactionCreation.name,
mockNow(),
() => {
@@ -1460,13 +1454,13 @@ describe('Profiler', () => {
},
);
expect(onInteractionTracked).toHaveBeenCalledTimes(1);
expect(onInteractionTracked).toHaveBeenLastNotifiedOfInteraction(
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
expect(onInteractionTraced).toHaveBeenLastNotifiedOfInteraction(
interactionCreation,
);
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();
// The schedule/tracking package will notify of work started for the default thread,
// The schedule/tracing package will notify of work started for the default thread,
// But React shouldn't notify until it's been flushed.
expect(getWorkForReactThreads(onWorkStarted)).toHaveLength(0);
expect(getWorkForReactThreads(onWorkStopped)).toHaveLength(0);
@@ -1486,11 +1480,11 @@ describe('Profiler', () => {
let call = onRender.mock.calls[0];
expect(call[0]).toEqual('test-profiler');
expect(call[5]).toEqual(mockNow());
if (ReactFeatureFlags.enableSchedulerTracking) {
if (ReactFeatureFlags.enableSchedulerTracing) {
expect(call[6]).toMatchInteractions([interactionCreation]);
}
expect(onInteractionTracked).toHaveBeenCalledTimes(1);
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1);
expect(
onInteractionScheduledWorkCompleted,
@@ -1518,13 +1512,13 @@ describe('Profiler', () => {
name: 'initial event',
timestamp: mockNow(),
};
SchedulerTracking.unstable_track(interactionOne.name, mockNow(), () => {
SchedulerTracing.unstable_trace(interactionOne.name, mockNow(), () => {
instance.setState({count: 1});
// Update state again to verify our tracked interaction isn't registered twice
// Update state again to verify our traced interaction isn't registered twice
instance.setState({count: 2});
// The schedule/tracking package will notify of work started for the default thread,
// The schedule/tracing package will notify of work started for the default thread,
// But React shouldn't notify until it's been flushed.
expect(getWorkForReactThreads(onWorkStarted)).toHaveLength(0);
expect(getWorkForReactThreads(onWorkStopped)).toHaveLength(0);
@@ -1541,8 +1535,8 @@ describe('Profiler', () => {
expect(renderer).toFlushThrough(['first']);
expect(onRender).not.toHaveBeenCalled();
expect(onInteractionTracked).toHaveBeenCalledTimes(2);
expect(onInteractionTracked).toHaveBeenLastNotifiedOfInteraction(
expect(onInteractionTraced).toHaveBeenCalledTimes(2);
expect(onInteractionTraced).toHaveBeenLastNotifiedOfInteraction(
interactionOne,
);
expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1);
@@ -1558,7 +1552,7 @@ describe('Profiler', () => {
call = onRender.mock.calls[0];
expect(call[0]).toEqual('test-profiler');
expect(call[5]).toEqual(mockNow());
if (ReactFeatureFlags.enableSchedulerTracking) {
if (ReactFeatureFlags.enableSchedulerTracing) {
expect(call[6]).toMatchInteractions([interactionOne]);
}
@@ -1591,11 +1585,11 @@ describe('Profiler', () => {
call = onRender.mock.calls[0];
expect(call[0]).toEqual('test-profiler');
expect(call[5]).toEqual(mockNow());
if (ReactFeatureFlags.enableSchedulerTracking) {
if (ReactFeatureFlags.enableSchedulerTracing) {
expect(call[6]).toMatchInteractions([]);
}
expect(onInteractionTracked).toHaveBeenCalledTimes(2);
expect(onInteractionTraced).toHaveBeenCalledTimes(2);
expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(2);
expect(
onInteractionScheduledWorkCompleted,
@@ -1607,13 +1601,13 @@ describe('Profiler', () => {
advanceTimeBy(3);
// Verify that root updates are also associated with tracked events.
// Verify that root updates are also associated with traced events.
const interactionTwo = {
id: 2,
name: 'root update event',
timestamp: mockNow(),
};
SchedulerTracking.unstable_track(interactionTwo.name, mockNow(), () => {
SchedulerTracing.unstable_trace(interactionTwo.name, mockNow(), () => {
renderer.update(
<React.unstable_Profiler id="test-profiler" onRender={onRender}>
<Example />
@@ -1621,13 +1615,13 @@ describe('Profiler', () => {
);
});
expect(onInteractionTracked).toHaveBeenCalledTimes(3);
expect(onInteractionTracked).toHaveBeenLastNotifiedOfInteraction(
expect(onInteractionTraced).toHaveBeenCalledTimes(3);
expect(onInteractionTraced).toHaveBeenLastNotifiedOfInteraction(
interactionTwo,
);
expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(2);
// The schedule/tracking package will notify of work started for the default thread,
// The schedule/tracing package will notify of work started for the default thread,
// But React shouldn't notify until it's been flushed.
expect(getWorkForReactThreads(onWorkStarted)).toHaveLength(0);
expect(getWorkForReactThreads(onWorkStopped)).toHaveLength(0);
@@ -1647,11 +1641,11 @@ describe('Profiler', () => {
call = onRender.mock.calls[0];
expect(call[0]).toEqual('test-profiler');
expect(call[5]).toEqual(mockNow());
if (ReactFeatureFlags.enableSchedulerTracking) {
if (ReactFeatureFlags.enableSchedulerTracing) {
expect(call[6]).toMatchInteractions([interactionTwo]);
}
expect(onInteractionTracked).toHaveBeenCalledTimes(3);
expect(onInteractionTraced).toHaveBeenCalledTimes(3);
expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(3);
expect(
onInteractionScheduledWorkCompleted,
@@ -1701,7 +1695,7 @@ describe('Profiler', () => {
// Initial mount.
renderer.unstable_flushAll(['FirstComponent', 'SecondComponent']);
expect(onInteractionTracked).not.toHaveBeenCalled();
expect(onInteractionTraced).not.toHaveBeenCalled();
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();
onRender.mockClear();
@@ -1714,121 +1708,115 @@ describe('Profiler', () => {
timestamp: mockNow(),
};
SchedulerTracking.unstable_track(
interactionLowPri.name,
mockNow(),
() => {
// Render a partially update, but don't finish.
first.setState({count: 1});
SchedulerTracing.unstable_trace(interactionLowPri.name, mockNow(), () => {
// Render a partially update, but don't finish.
first.setState({count: 1});
expect(onWorkScheduled).toHaveBeenCalled();
expect(onWorkScheduled.mock.calls[0][0]).toMatchInteractions([
interactionLowPri,
]);
expect(onWorkScheduled).toHaveBeenCalled();
expect(onWorkScheduled.mock.calls[0][0]).toMatchInteractions([
interactionLowPri,
]);
expect(renderer).toFlushThrough(['FirstComponent']);
expect(onRender).not.toHaveBeenCalled();
expect(renderer).toFlushThrough(['FirstComponent']);
expect(onRender).not.toHaveBeenCalled();
expect(onInteractionTracked).toHaveBeenCalledTimes(1);
expect(onInteractionTracked).toHaveBeenLastNotifiedOfInteraction(
interactionLowPri,
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
expect(onInteractionTraced).toHaveBeenLastNotifiedOfInteraction(
interactionLowPri,
);
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();
expect(getWorkForReactThreads(onWorkStarted)).toHaveLength(1);
expect(getWorkForReactThreads(onWorkStarted)[0][0]).toMatchInteractions(
[interactionLowPri],
);
expect(getWorkForReactThreads(onWorkStopped)).toHaveLength(0);
advanceTimeBy(100);
const interactionHighPri = {
id: 1,
name: 'highPri',
timestamp: mockNow(),
};
// Interrupt with higher priority work.
// This simulates a total of 37ms of actual render time.
renderer.unstable_flushSync(() => {
SchedulerTracing.unstable_trace(
interactionHighPri.name,
mockNow(),
() => {
second.setState({count: 1});
expect(onInteractionTraced).toHaveBeenCalledTimes(2);
expect(onInteractionTraced).toHaveBeenLastNotifiedOfInteraction(
interactionHighPri,
);
expect(
onInteractionScheduledWorkCompleted,
).not.toHaveBeenCalled();
expect(getWorkForReactThreads(onWorkStarted)).toHaveLength(1);
expect(getWorkForReactThreads(onWorkStopped)).toHaveLength(0);
},
);
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();
expect(getWorkForReactThreads(onWorkStarted)).toHaveLength(1);
expect(
getWorkForReactThreads(onWorkStarted)[0][0],
).toMatchInteractions([interactionLowPri]);
expect(getWorkForReactThreads(onWorkStopped)).toHaveLength(0);
});
expect(ReactTestRenderer).toClearYields(['SecondComponent']);
advanceTimeBy(100);
expect(onInteractionTraced).toHaveBeenCalledTimes(2);
expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1);
expect(
onInteractionScheduledWorkCompleted,
).toHaveBeenLastNotifiedOfInteraction(interactionHighPri);
const interactionHighPri = {
id: 1,
name: 'highPri',
timestamp: mockNow(),
};
// Verify the high priority update was associated with the high priority event.
expect(onRender).toHaveBeenCalledTimes(1);
let call = onRender.mock.calls[0];
expect(call[0]).toEqual('test');
expect(call[5]).toEqual(mockNow());
expect(call[6]).toMatchInteractions(
ReactFeatureFlags.enableSchedulerTracing
? [interactionLowPri, interactionHighPri]
: [],
);
// Interrupt with higher priority work.
// This simulates a total of 37ms of actual render time.
renderer.unstable_flushSync(() => {
SchedulerTracking.unstable_track(
interactionHighPri.name,
mockNow(),
() => {
second.setState({count: 1});
onRender.mockClear();
expect(onInteractionTracked).toHaveBeenCalledTimes(2);
expect(
onInteractionTracked,
).toHaveBeenLastNotifiedOfInteraction(interactionHighPri);
expect(
onInteractionScheduledWorkCompleted,
).not.toHaveBeenCalled();
advanceTimeBy(100);
expect(getWorkForReactThreads(onWorkStarted)).toHaveLength(1);
expect(getWorkForReactThreads(onWorkStopped)).toHaveLength(0);
},
);
});
expect(ReactTestRenderer).toClearYields(['SecondComponent']);
// Resume the original low priority update, with rebased state.
// Verify the low priority update was retained.
renderer.unstable_flushAll(['FirstComponent']);
expect(onRender).toHaveBeenCalledTimes(1);
call = onRender.mock.calls[0];
expect(call[0]).toEqual('test');
expect(call[5]).toEqual(mockNow());
expect(call[6]).toMatchInteractions(
ReactFeatureFlags.enableSchedulerTracing ? [interactionLowPri] : [],
);
expect(onInteractionTracked).toHaveBeenCalledTimes(2);
expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1);
expect(
onInteractionScheduledWorkCompleted,
).toHaveBeenLastNotifiedOfInteraction(interactionHighPri);
expect(onInteractionTraced).toHaveBeenCalledTimes(2);
expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1);
// Verify the high priority update was associated with the high priority event.
expect(onRender).toHaveBeenCalledTimes(1);
let call = onRender.mock.calls[0];
expect(call[0]).toEqual('test');
expect(call[5]).toEqual(mockNow());
expect(call[6]).toMatchInteractions(
ReactFeatureFlags.enableSchedulerTracking
? [interactionLowPri, interactionHighPri]
: [],
);
// Work might be started multiple times before being completed.
// This is okay; it's part of the schedule/tracing contract.
expect(getWorkForReactThreads(onWorkStarted)).toHaveLength(3);
expect(getWorkForReactThreads(onWorkStarted)[1][0]).toMatchInteractions(
[interactionLowPri, interactionHighPri],
);
expect(getWorkForReactThreads(onWorkStarted)[2][0]).toMatchInteractions(
[interactionLowPri],
);
expect(getWorkForReactThreads(onWorkStopped)).toHaveLength(2);
expect(getWorkForReactThreads(onWorkStopped)[0][0]).toMatchInteractions(
[interactionLowPri, interactionHighPri],
);
expect(getWorkForReactThreads(onWorkStopped)[1][0]).toMatchInteractions(
[interactionLowPri],
);
});
onRender.mockClear();
advanceTimeBy(100);
// Resume the original low priority update, with rebased state.
// Verify the low priority update was retained.
renderer.unstable_flushAll(['FirstComponent']);
expect(onRender).toHaveBeenCalledTimes(1);
call = onRender.mock.calls[0];
expect(call[0]).toEqual('test');
expect(call[5]).toEqual(mockNow());
expect(call[6]).toMatchInteractions(
ReactFeatureFlags.enableSchedulerTracking
? [interactionLowPri]
: [],
);
expect(onInteractionTracked).toHaveBeenCalledTimes(2);
expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1);
// Work might be started multiple times before being completed.
// This is okay; it's part of the schedule/tracking contract.
expect(getWorkForReactThreads(onWorkStarted)).toHaveLength(3);
expect(
getWorkForReactThreads(onWorkStarted)[1][0],
).toMatchInteractions([interactionLowPri, interactionHighPri]);
expect(
getWorkForReactThreads(onWorkStarted)[2][0],
).toMatchInteractions([interactionLowPri]);
expect(getWorkForReactThreads(onWorkStopped)).toHaveLength(2);
expect(
getWorkForReactThreads(onWorkStopped)[0][0],
).toMatchInteractions([interactionLowPri, interactionHighPri]);
expect(
getWorkForReactThreads(onWorkStopped)[1][0],
).toMatchInteractions([interactionLowPri]);
},
);
expect(onInteractionTracked).toHaveBeenCalledTimes(2);
expect(onInteractionTraced).toHaveBeenCalledTimes(2);
expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(2);
expect(
onInteractionScheduledWorkCompleted,
@@ -1837,7 +1825,7 @@ describe('Profiler', () => {
expect(getWorkForReactThreads(onWorkStopped)).toHaveLength(2);
});
it('should track work spawned by a commit phase lifecycle and setState callback', () => {
it('should trace work spawned by a commit phase lifecycle and setState callback', () => {
let instance;
class Example extends React.Component {
state = {
@@ -1870,7 +1858,7 @@ describe('Profiler', () => {
const onRender = jest.fn();
let firstCommitTime = mockNow();
let renderer;
SchedulerTracking.unstable_track(interactionOne.name, mockNow(), () => {
SchedulerTracing.unstable_trace(interactionOne.name, mockNow(), () => {
renderer = ReactTestRenderer.create(
<React.unstable_Profiler id="test" onRender={onRender}>
<Example />
@@ -1879,8 +1867,8 @@ describe('Profiler', () => {
);
});
expect(onInteractionTracked).toHaveBeenCalledTimes(1);
expect(onInteractionTracked).toHaveBeenLastNotifiedOfInteraction(
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
expect(onInteractionTraced).toHaveBeenLastNotifiedOfInteraction(
interactionOne,
);
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();
@@ -1889,7 +1877,7 @@ describe('Profiler', () => {
renderer.unstable_flushAll(['Example:0', 'Example:1']);
expect(onInteractionTracked).toHaveBeenCalledTimes(1);
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1);
expect(
onInteractionScheduledWorkCompleted,
@@ -1914,13 +1902,13 @@ describe('Profiler', () => {
expect(call[0]).toEqual('test');
expect(call[5]).toEqual(firstCommitTime);
expect(call[6]).toMatchInteractions(
ReactFeatureFlags.enableSchedulerTracking ? [interactionOne] : [],
ReactFeatureFlags.enableSchedulerTracing ? [interactionOne] : [],
);
call = onRender.mock.calls[1];
expect(call[0]).toEqual('test');
expect(call[5]).toEqual(mockNow());
expect(call[6]).toMatchInteractions(
ReactFeatureFlags.enableSchedulerTracking ? [interactionOne] : [],
ReactFeatureFlags.enableSchedulerTracing ? [interactionOne] : [],
);
onRender.mockClear();
@@ -1931,13 +1919,13 @@ describe('Profiler', () => {
timestamp: mockNow(),
};
// Cause an tracked, async update
SchedulerTracking.unstable_track(interactionTwo.name, mockNow(), () => {
// Cause an traced, async update
SchedulerTracing.unstable_trace(interactionTwo.name, mockNow(), () => {
instance.setState({count: 2});
});
expect(onRender).not.toHaveBeenCalled();
expect(onInteractionTracked).toHaveBeenCalledTimes(2);
expect(onInteractionTracked).toHaveBeenLastNotifiedOfInteraction(
expect(onInteractionTraced).toHaveBeenCalledTimes(2);
expect(onInteractionTraced).toHaveBeenLastNotifiedOfInteraction(
interactionTwo,
);
expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1);
@@ -1946,12 +1934,12 @@ describe('Profiler', () => {
advanceTimeBy(5);
// Flush async work (outside of tracked scope)
// Flush async work (outside of traced scope)
// This will cause an intentional cascading update from did-update
firstCommitTime = mockNow();
renderer.unstable_flushAll(['Example:2', 'Example:3']);
expect(onInteractionTracked).toHaveBeenCalledTimes(2);
expect(onInteractionTraced).toHaveBeenCalledTimes(2);
expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(2);
expect(
onInteractionScheduledWorkCompleted,
@@ -1977,13 +1965,13 @@ describe('Profiler', () => {
expect(call[0]).toEqual('test');
expect(call[5]).toEqual(firstCommitTime);
expect(call[6]).toMatchInteractions(
ReactFeatureFlags.enableSchedulerTracking ? [interactionTwo] : [],
ReactFeatureFlags.enableSchedulerTracing ? [interactionTwo] : [],
);
call = onRender.mock.calls[1];
expect(call[0]).toEqual('test');
expect(call[5]).toEqual(mockNow());
expect(call[6]).toMatchInteractions(
ReactFeatureFlags.enableSchedulerTracking ? [interactionTwo] : [],
ReactFeatureFlags.enableSchedulerTracing ? [interactionTwo] : [],
);
onRender.mockClear();
@@ -1998,25 +1986,25 @@ describe('Profiler', () => {
function callback() {
instance.setState({count: 6});
}
SchedulerTracking.unstable_track(interactionThree.name, mockNow(), () => {
SchedulerTracing.unstable_trace(interactionThree.name, mockNow(), () => {
instance.setState({count: 5}, callback);
});
expect(onRender).not.toHaveBeenCalled();
expect(onInteractionTracked).toHaveBeenCalledTimes(3);
expect(onInteractionTracked).toHaveBeenLastNotifiedOfInteraction(
expect(onInteractionTraced).toHaveBeenCalledTimes(3);
expect(onInteractionTraced).toHaveBeenLastNotifiedOfInteraction(
interactionThree,
);
expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(2);
expect(getWorkForReactThreads(onWorkStarted)).toHaveLength(4);
expect(getWorkForReactThreads(onWorkStopped)).toHaveLength(4);
// Flush async work (outside of tracked scope)
// Flush async work (outside of traced scope)
// This will cause an intentional cascading update from the setState callback
firstCommitTime = mockNow();
renderer.unstable_flushAll(['Example:5', 'Example:6']);
expect(onInteractionTracked).toHaveBeenCalledTimes(3);
expect(onInteractionTraced).toHaveBeenCalledTimes(3);
expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(3);
expect(
onInteractionScheduledWorkCompleted,
@@ -2042,17 +2030,17 @@ describe('Profiler', () => {
expect(call[0]).toEqual('test');
expect(call[5]).toEqual(firstCommitTime);
expect(call[6]).toMatchInteractions(
ReactFeatureFlags.enableSchedulerTracking ? [interactionThree] : [],
ReactFeatureFlags.enableSchedulerTracing ? [interactionThree] : [],
);
call = onRender.mock.calls[1];
expect(call[0]).toEqual('test');
expect(call[5]).toEqual(mockNow());
expect(call[6]).toMatchInteractions(
ReactFeatureFlags.enableSchedulerTracking ? [interactionThree] : [],
ReactFeatureFlags.enableSchedulerTracing ? [interactionThree] : [],
);
});
it('should track interactions associated with a parent component state update', () => {
it('should trace interactions associated with a parent component state update', () => {
const onRender = jest.fn();
let parentInstance = null;
@@ -2091,12 +2079,12 @@ describe('Profiler', () => {
timestamp: mockNow(),
};
SchedulerTracking.unstable_track(interaction.name, mockNow(), () => {
SchedulerTracing.unstable_trace(interaction.name, mockNow(), () => {
parentInstance.setState({count: 1});
});
expect(onInteractionTracked).toHaveBeenCalledTimes(1);
expect(onInteractionTracked).toHaveBeenLastNotifiedOfInteraction(
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
expect(onInteractionTraced).toHaveBeenLastNotifiedOfInteraction(
interaction,
);
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();
@@ -2109,10 +2097,10 @@ describe('Profiler', () => {
let call = onRender.mock.calls[0];
expect(call[0]).toEqual('test-profiler');
expect(call[6]).toMatchInteractions(
ReactFeatureFlags.enableSchedulerTracking ? [interaction] : [],
ReactFeatureFlags.enableSchedulerTracing ? [interaction] : [],
);
expect(onInteractionTracked).toHaveBeenCalledTimes(1);
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1);
expect(
onInteractionScheduledWorkCompleted,
@@ -2127,19 +2115,19 @@ describe('Profiler', () => {
]);
});
it('tracks both the temporary placeholder and the finished render for an interaction', async () => {
it('traces both the temporary placeholder and the finished render for an interaction', async () => {
jest.resetModules();
loadModules({
useNoopRenderer: true,
enableSuspense: true,
enableSchedulerTracking: true,
enableSchedulerTracing: true,
});
// Re-register since we've reloaded modules
SchedulerTracking.unstable_subscribe({
SchedulerTracing.unstable_subscribe({
onInteractionScheduledWorkCompleted,
onInteractionTracked,
onInteractionTraced,
onWorkCanceled,
onWorkScheduled,
onWorkStarted,
@@ -2204,7 +2192,7 @@ describe('Profiler', () => {
};
const onRender = jest.fn();
SchedulerTracking.unstable_track(interaction.name, mockNow(), () => {
SchedulerTracing.unstable_trace(interaction.name, mockNow(), () => {
ReactNoop.render(
<React.unstable_Profiler id="test-profiler" onRender={onRender}>
<React.Placeholder fallback={<Text text="Loading..." />}>
@@ -2215,8 +2203,8 @@ describe('Profiler', () => {
);
});
expect(onInteractionTracked).toHaveBeenCalledTimes(1);
expect(onInteractionTracked).toHaveBeenLastNotifiedOfInteraction(
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
expect(onInteractionTraced).toHaveBeenLastNotifiedOfInteraction(
interaction,
);
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();
@@ -2249,10 +2237,10 @@ describe('Profiler', () => {
let call = onRender.mock.calls[0];
expect(call[0]).toEqual('test-profiler');
expect(call[6]).toMatchInteractions(
ReactFeatureFlags.enableSchedulerTracking ? [interaction] : [],
ReactFeatureFlags.enableSchedulerTracing ? [interaction] : [],
);
expect(onInteractionTracked).toHaveBeenCalledTimes(1);
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();
// Once the promise resolves, we render the suspended view
@@ -2264,10 +2252,10 @@ describe('Profiler', () => {
call = onRender.mock.calls[1];
expect(call[0]).toEqual('test-profiler');
expect(call[6]).toMatchInteractions(
ReactFeatureFlags.enableSchedulerTracking ? [interaction] : [],
ReactFeatureFlags.enableSchedulerTracing ? [interaction] : [],
);
expect(onInteractionTracked).toHaveBeenCalledTimes(1);
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1);
expect(
onInteractionScheduledWorkCompleted,
@@ -14,7 +14,7 @@ describe('ReactProfiler DevTools integration', () => {
let React;
let ReactFeatureFlags;
let ReactTestRenderer;
let SchedulerTracking;
let SchedulerTracing;
let AdvanceTime;
let advanceTimeBy;
let hook;
@@ -38,8 +38,8 @@ describe('ReactProfiler DevTools integration', () => {
ReactFeatureFlags = require('shared/ReactFeatureFlags');
ReactFeatureFlags.enableProfilerTimer = true;
ReactFeatureFlags.enableSchedulerTracking = true;
SchedulerTracking = require('schedule/tracking');
ReactFeatureFlags.enableSchedulerTracing = true;
SchedulerTracing = require('schedule/tracing');
React = require('react');
ReactTestRenderer = require('react-test-renderer');
@@ -168,7 +168,7 @@ describe('ReactProfiler DevTools integration', () => {
).toBe(7);
});
it('should store tracked interactions on the HostNode so DevTools can access them', () => {
it('should store traced interactions on the HostNode so DevTools can access them', () => {
// Render without an interaction
const rendered = ReactTestRenderer.create(<div />);
@@ -180,7 +180,7 @@ describe('ReactProfiler DevTools integration', () => {
const eventTime = mockNow();
// Render with an interaction
SchedulerTracking.unstable_track('some event', eventTime, () => {
SchedulerTracing.unstable_trace('some event', eventTime, () => {
rendered.update(<div />);
});
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracking:disabled enableProfilerTimer:disabled should render children 1`] = `
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracing:disabled enableProfilerTimer:disabled should render children 1`] = `
<div>
<span>
outside span
@@ -14,11 +14,11 @@ exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTr
</div>
`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracking:disabled enableProfilerTimer:disabled should support an empty Profiler (with no children) 1`] = `null`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracing:disabled enableProfilerTimer:disabled should support an empty Profiler (with no children) 1`] = `null`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracking:disabled enableProfilerTimer:disabled should support an empty Profiler (with no children) 2`] = `<div />`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracing:disabled enableProfilerTimer:disabled should support an empty Profiler (with no children) 2`] = `<div />`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracking:disabled enableProfilerTimer:disabled should support nested Profilers 1`] = `
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracing:disabled enableProfilerTimer:disabled should support nested Profilers 1`] = `
Array [
<div>
outer functional component
@@ -32,7 +32,7 @@ Array [
]
`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracking:disabled enableProfilerTimer:enabled should render children 1`] = `
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracing:disabled enableProfilerTimer:enabled should render children 1`] = `
<div>
<span>
outside span
@@ -46,11 +46,11 @@ exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTr
</div>
`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracking:disabled enableProfilerTimer:enabled should support an empty Profiler (with no children) 1`] = `null`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracing:disabled enableProfilerTimer:enabled should support an empty Profiler (with no children) 1`] = `null`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracking:disabled enableProfilerTimer:enabled should support an empty Profiler (with no children) 2`] = `<div />`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracing:disabled enableProfilerTimer:enabled should support an empty Profiler (with no children) 2`] = `<div />`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracking:disabled enableProfilerTimer:enabled should support nested Profilers 1`] = `
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracing:disabled enableProfilerTimer:enabled should support nested Profilers 1`] = `
Array [
<div>
outer functional component
@@ -64,7 +64,7 @@ Array [
]
`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracking:enabled enableProfilerTimer:disabled should render children 1`] = `
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracing:enabled enableProfilerTimer:disabled should render children 1`] = `
<div>
<span>
outside span
@@ -78,11 +78,11 @@ exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTr
</div>
`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracking:enabled enableProfilerTimer:disabled should support an empty Profiler (with no children) 1`] = `null`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracing:enabled enableProfilerTimer:disabled should support an empty Profiler (with no children) 1`] = `null`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracking:enabled enableProfilerTimer:disabled should support an empty Profiler (with no children) 2`] = `<div />`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracing:enabled enableProfilerTimer:disabled should support an empty Profiler (with no children) 2`] = `<div />`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracking:enabled enableProfilerTimer:disabled should support nested Profilers 1`] = `
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracing:enabled enableProfilerTimer:disabled should support nested Profilers 1`] = `
Array [
<div>
outer functional component
@@ -96,7 +96,7 @@ Array [
]
`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracking:enabled enableProfilerTimer:enabled should render children 1`] = `
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracing:enabled enableProfilerTimer:enabled should render children 1`] = `
<div>
<span>
outside span
@@ -110,11 +110,11 @@ exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTr
</div>
`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracking:enabled enableProfilerTimer:enabled should support an empty Profiler (with no children) 1`] = `null`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracing:enabled enableProfilerTimer:enabled should support an empty Profiler (with no children) 1`] = `null`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracking:enabled enableProfilerTimer:enabled should support an empty Profiler (with no children) 2`] = `<div />`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracing:enabled enableProfilerTimer:enabled should support an empty Profiler (with no children) 2`] = `<div />`;
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracking:enabled enableProfilerTimer:enabled should support nested Profilers 1`] = `
exports[`Profiler works in profiling and non-profiling bundles enableSchedulerTracing:enabled enableProfilerTimer:enabled should support nested Profilers 1`] = `
Array [
<div>
outer functional component
@@ -0,0 +1,7 @@
'use strict';
if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/schedule-tracing.profiling.min.js');
} else {
module.exports = require('./cjs/schedule-tracing.development.js');
}
+7
View File
@@ -0,0 +1,7 @@
'use strict';
if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/schedule-tracing.production.min.js');
} else {
module.exports = require('./cjs/schedule-tracing.development.js');
}
@@ -1,7 +0,0 @@
'use strict';
if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/schedule-tracking.profiling.min.js');
} else {
module.exports = require('./cjs/schedule-tracking.development.js');
}
-7
View File
@@ -1,7 +0,0 @@
'use strict';
if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/schedule-tracking.production.min.js');
} else {
module.exports = require('./cjs/schedule-tracking.development.js');
}
@@ -14,24 +14,24 @@
? (module.exports = factory(require('react')))
: typeof define === 'function' && define.amd // eslint-disable-line no-undef
? define(['react'], factory) // eslint-disable-line no-undef
: (global.ScheduleTracking = factory(global));
: (global.ScheduleTracing = factory(global));
})(this, function(global) {
function unstable_clear() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.unstable_clear.apply(
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_clear.apply(
this,
arguments
);
}
function unstable_getCurrent() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.unstable_getCurrent.apply(
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_getCurrent.apply(
this,
arguments
);
}
function unstable_getThreadID() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.unstable_getThreadID.apply(
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_getThreadID.apply(
this,
arguments
);
@@ -39,14 +39,14 @@
function unstable_subscribe() {
// eslint-disable-next-line max-len
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.unstable_subscribe.apply(
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_subscribe.apply(
this,
arguments
);
}
function unstable_track() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.unstable_track.apply(
function unstable_trace() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_trace.apply(
this,
arguments
);
@@ -54,14 +54,14 @@
function unstable_unsubscribe() {
// eslint-disable-next-line max-len
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.unstable_unsubscribe.apply(
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_unsubscribe.apply(
this,
arguments
);
}
function unstable_wrap() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.unstable_wrap.apply(
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_wrap.apply(
this,
arguments
);
@@ -72,7 +72,7 @@
unstable_getCurrent: unstable_getCurrent,
unstable_getThreadID: unstable_getThreadID,
unstable_subscribe: unstable_subscribe,
unstable_track: unstable_track,
unstable_trace: unstable_trace,
unstable_unsubscribe: unstable_unsubscribe,
unstable_wrap: unstable_wrap,
});
@@ -14,24 +14,24 @@
? (module.exports = factory(require('react')))
: typeof define === 'function' && define.amd // eslint-disable-line no-undef
? define(['react'], factory) // eslint-disable-line no-undef
: (global.ScheduleTracking = factory(global));
: (global.ScheduleTracing = factory(global));
})(this, function(global) {
function unstable_clear() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.unstable_clear.apply(
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_clear.apply(
this,
arguments
);
}
function unstable_getCurrent() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.unstable_getCurrent.apply(
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_getCurrent.apply(
this,
arguments
);
}
function unstable_getThreadID() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.unstable_getThreadID.apply(
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_getThreadID.apply(
this,
arguments
);
@@ -39,14 +39,14 @@
function unstable_subscribe() {
// eslint-disable-next-line max-len
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.unstable_subscribe.apply(
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_subscribe.apply(
this,
arguments
);
}
function unstable_track() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.unstable_track.apply(
function unstable_trace() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_trace.apply(
this,
arguments
);
@@ -54,14 +54,14 @@
function unstable_unsubscribe() {
// eslint-disable-next-line max-len
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.unstable_unsubscribe.apply(
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_unsubscribe.apply(
this,
arguments
);
}
function unstable_wrap() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.unstable_wrap.apply(
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_wrap.apply(
this,
arguments
);
@@ -72,7 +72,7 @@
unstable_getCurrent: unstable_getCurrent,
unstable_getThreadID: unstable_getThreadID,
unstable_subscribe: unstable_subscribe,
unstable_track: unstable_track,
unstable_trace: unstable_trace,
unstable_unsubscribe: unstable_unsubscribe,
unstable_wrap: unstable_wrap,
});
+2 -2
View File
@@ -19,8 +19,8 @@
"LICENSE",
"README.md",
"index.js",
"tracking.js",
"tracking-profiling.js",
"tracing.js",
"tracing-profiling.js",
"cjs/",
"umd/"
]
@@ -7,7 +7,7 @@
* @flow
*/
import {enableSchedulerTracking} from 'shared/ReactFeatureFlags';
import {enableSchedulerTracing} from 'shared/ReactFeatureFlags';
export type Interaction = {|
__count: number,
@@ -17,8 +17,8 @@ export type Interaction = {|
|};
export type Subscriber = {
// A new interaction has been created via the track() method.
onInteractionTracked: (interaction: Interaction) => void,
// A new interaction has been created via the trace() method.
onInteractionTraced: (interaction: Interaction) => void,
// All scheduled async work for an interaction has finished.
onInteractionScheduledWorkCompleted: (interaction: Interaction) => void,
@@ -61,16 +61,16 @@ const DEFAULT_THREAD_ID = 0;
let interactionIDCounter: number = 0;
let threadIDCounter: number = 0;
// Set of currently tracked interactions.
// Set of currently traced interactions.
// Interactions "stack"–
// Meaning that newly tracked interactions are appended to the previously active set.
// Meaning that newly traced interactions are appended to the previously active set.
// When an interaction goes out of scope, the previous set (if any) is restored.
let interactionsRef: InteractionsRef = (null: any);
// Listener(s) to notify when interactions begin and end.
let subscriberRef: SubscriberRef = (null: any);
if (enableSchedulerTracking) {
if (enableSchedulerTracing) {
interactionsRef = {
current: new Set(),
};
@@ -82,7 +82,7 @@ if (enableSchedulerTracking) {
export {interactionsRef as __interactionsRef, subscriberRef as __subscriberRef};
export function unstable_clear(callback: Function): any {
if (!enableSchedulerTracking) {
if (!enableSchedulerTracing) {
return callback();
}
@@ -97,7 +97,7 @@ export function unstable_clear(callback: Function): any {
}
export function unstable_getCurrent(): Set<Interaction> | null {
if (!enableSchedulerTracking) {
if (!enableSchedulerTracing) {
return null;
} else {
return interactionsRef.current;
@@ -108,13 +108,13 @@ export function unstable_getThreadID(): number {
return ++threadIDCounter;
}
export function unstable_track(
export function unstable_trace(
name: string,
timestamp: number,
callback: Function,
threadID: number = DEFAULT_THREAD_ID,
): any {
if (!enableSchedulerTracking) {
if (!enableSchedulerTracing) {
return callback();
}
@@ -127,7 +127,7 @@ export function unstable_track(
const prevInteractions = interactionsRef.current;
// Tracked interactions should stack/accumulate.
// Traced interactions should stack/accumulate.
// To do that, clone the current interactions.
// The previous set will be restored upon completion.
const interactions = new Set(prevInteractions);
@@ -139,7 +139,7 @@ export function unstable_track(
try {
if (subscriber !== null) {
subscriber.onInteractionTracked(interaction);
subscriber.onInteractionTraced(interaction);
}
} finally {
try {
@@ -176,7 +176,7 @@ export function unstable_wrap(
callback: Function,
threadID: number = DEFAULT_THREAD_ID,
): Function {
if (!enableSchedulerTracking) {
if (!enableSchedulerTracing) {
return callback;
}
@@ -7,24 +7,24 @@
* @flow
*/
import type {Interaction, Subscriber} from './Tracking';
import type {Interaction, Subscriber} from './Tracing';
import {enableSchedulerTracking} from 'shared/ReactFeatureFlags';
import {__subscriberRef} from 'schedule/tracking';
import {enableSchedulerTracing} from 'shared/ReactFeatureFlags';
import {__subscriberRef} from 'schedule/tracing';
let subscribers: Set<Subscriber> = (null: any);
if (enableSchedulerTracking) {
if (enableSchedulerTracing) {
subscribers = new Set();
}
export function unstable_subscribe(subscriber: Subscriber): void {
if (enableSchedulerTracking) {
if (enableSchedulerTracing) {
subscribers.add(subscriber);
if (subscribers.size === 1) {
__subscriberRef.current = {
onInteractionScheduledWorkCompleted,
onInteractionTracked,
onInteractionTraced,
onWorkCanceled,
onWorkScheduled,
onWorkStarted,
@@ -35,7 +35,7 @@ export function unstable_subscribe(subscriber: Subscriber): void {
}
export function unstable_unsubscribe(subscriber: Subscriber): void {
if (enableSchedulerTracking) {
if (enableSchedulerTracing) {
subscribers.delete(subscriber);
if (subscribers.size === 0) {
@@ -44,13 +44,13 @@ export function unstable_unsubscribe(subscriber: Subscriber): void {
}
}
function onInteractionTracked(interaction: Interaction): void {
function onInteractionTraced(interaction: Interaction): void {
let didCatchError = false;
let caughtError = null;
subscribers.forEach(subscriber => {
try {
subscriber.onInteractionTracked(interaction);
subscriber.onInteractionTraced(interaction);
} catch (error) {
if (!didCatchError) {
didCatchError = true;
@@ -41,15 +41,15 @@ describe('Scheduling UMD bundle', () => {
validateForwardedAPIs(api, [umdAPIDev, umdAPIProd, secretAPI.Schedule]);
});
it('should define the same tracking API', () => {
const api = require('../../tracking');
const umdAPIDev = require('../../npm/umd/schedule-tracking.development');
const umdAPIProd = require('../../npm/umd/schedule-tracking.production.min');
it('should define the same tracing API', () => {
const api = require('../../tracing');
const umdAPIDev = require('../../npm/umd/schedule-tracing.development');
const umdAPIProd = require('../../npm/umd/schedule-tracing.production.min');
const secretAPI = require('react/src/ReactSharedInternals').default;
validateForwardedAPIs(api, [
umdAPIDev,
umdAPIProd,
secretAPI.ScheduleTracking,
secretAPI.ScheduleTracing,
]);
});
});
@@ -0,0 +1,375 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment node
*/
'use strict';
describe('Tracing', () => {
let SchedulerTracing;
let ReactFeatureFlags;
let advanceTimeBy;
let currentTime;
function loadModules({enableSchedulerTracing}) {
jest.resetModules();
jest.useFakeTimers();
currentTime = 0;
Date.now = jest.fn().mockImplementation(() => currentTime);
advanceTimeBy = amount => {
currentTime += amount;
};
ReactFeatureFlags = require('shared/ReactFeatureFlags');
ReactFeatureFlags.enableSchedulerTracing = enableSchedulerTracing;
SchedulerTracing = require('schedule/tracing');
}
describe('enableSchedulerTracing enabled', () => {
beforeEach(() => loadModules({enableSchedulerTracing: true}));
it('should return the value of a traced function', () => {
expect(
SchedulerTracing.unstable_trace('arbitrary', currentTime, () => 123),
).toBe(123);
});
it('should return the value of a clear function', () => {
expect(SchedulerTracing.unstable_clear(() => 123)).toBe(123);
});
it('should return the value of a wrapped function', () => {
let wrapped;
SchedulerTracing.unstable_trace('arbitrary', currentTime, () => {
wrapped = SchedulerTracing.unstable_wrap(() => 123);
});
expect(wrapped()).toBe(123);
});
it('should pass arguments through to a wrapped function', done => {
let wrapped;
SchedulerTracing.unstable_trace('arbitrary', currentTime, () => {
wrapped = SchedulerTracing.unstable_wrap((param1, param2) => {
expect(param1).toBe('foo');
expect(param2).toBe('bar');
done();
});
});
wrapped('foo', 'bar');
});
it('should return an empty set when outside of a traced event', () => {
expect(SchedulerTracing.unstable_getCurrent()).toContainNoInteractions();
});
it('should report the traced interaction from within the trace callback', done => {
advanceTimeBy(100);
SchedulerTracing.unstable_trace('some event', currentTime, () => {
const interactions = SchedulerTracing.unstable_getCurrent();
expect(interactions).toMatchInteractions([
{name: 'some event', timestamp: 100},
]);
done();
});
});
it('should report the traced interaction from within wrapped callbacks', done => {
let wrappedIndirection;
function indirection() {
const interactions = SchedulerTracing.unstable_getCurrent();
expect(interactions).toMatchInteractions([
{name: 'some event', timestamp: 100},
]);
done();
}
advanceTimeBy(100);
SchedulerTracing.unstable_trace('some event', currentTime, () => {
wrappedIndirection = SchedulerTracing.unstable_wrap(indirection);
});
advanceTimeBy(50);
wrappedIndirection();
});
it('should clear the interaction stack for traced callbacks', () => {
let innerTestReached = false;
SchedulerTracing.unstable_trace('outer event', currentTime, () => {
expect(SchedulerTracing.unstable_getCurrent()).toMatchInteractions([
{name: 'outer event'},
]);
SchedulerTracing.unstable_clear(() => {
expect(SchedulerTracing.unstable_getCurrent()).toMatchInteractions(
[],
);
SchedulerTracing.unstable_trace('inner event', currentTime, () => {
expect(SchedulerTracing.unstable_getCurrent()).toMatchInteractions([
{name: 'inner event'},
]);
innerTestReached = true;
});
});
expect(SchedulerTracing.unstable_getCurrent()).toMatchInteractions([
{name: 'outer event'},
]);
});
expect(innerTestReached).toBe(true);
});
it('should clear the interaction stack for wrapped callbacks', () => {
let innerTestReached = false;
let wrappedIndirection;
const indirection = jest.fn(() => {
expect(SchedulerTracing.unstable_getCurrent()).toMatchInteractions([
{name: 'outer event'},
]);
SchedulerTracing.unstable_clear(() => {
expect(SchedulerTracing.unstable_getCurrent()).toMatchInteractions(
[],
);
SchedulerTracing.unstable_trace('inner event', currentTime, () => {
expect(SchedulerTracing.unstable_getCurrent()).toMatchInteractions([
{name: 'inner event'},
]);
innerTestReached = true;
});
});
expect(SchedulerTracing.unstable_getCurrent()).toMatchInteractions([
{name: 'outer event'},
]);
});
SchedulerTracing.unstable_trace('outer event', currentTime, () => {
wrappedIndirection = SchedulerTracing.unstable_wrap(indirection);
});
wrappedIndirection();
expect(innerTestReached).toBe(true);
});
it('should support nested traced events', done => {
advanceTimeBy(100);
let innerIndirectionTraced = false;
let outerIndirectionTraced = false;
function innerIndirection() {
const interactions = SchedulerTracing.unstable_getCurrent();
expect(interactions).toMatchInteractions([
{name: 'outer event', timestamp: 100},
{name: 'inner event', timestamp: 150},
]);
innerIndirectionTraced = true;
}
function outerIndirection() {
const interactions = SchedulerTracing.unstable_getCurrent();
expect(interactions).toMatchInteractions([
{name: 'outer event', timestamp: 100},
]);
outerIndirectionTraced = true;
}
SchedulerTracing.unstable_trace('outer event', currentTime, () => {
// Verify the current traced event
let interactions = SchedulerTracing.unstable_getCurrent();
expect(interactions).toMatchInteractions([
{name: 'outer event', timestamp: 100},
]);
advanceTimeBy(50);
const wrapperOuterIndirection = SchedulerTracing.unstable_wrap(
outerIndirection,
);
let wrapperInnerIndirection;
let innerEventTraced = false;
// Verify that a nested event is properly traced
SchedulerTracing.unstable_trace('inner event', currentTime, () => {
interactions = SchedulerTracing.unstable_getCurrent();
expect(interactions).toMatchInteractions([
{name: 'outer event', timestamp: 100},
{name: 'inner event', timestamp: 150},
]);
// Verify that a wrapped outer callback is properly traced
wrapperOuterIndirection();
expect(outerIndirectionTraced).toBe(true);
wrapperInnerIndirection = SchedulerTracing.unstable_wrap(
innerIndirection,
);
innerEventTraced = true;
});
expect(innerEventTraced).toBe(true);
// Verify that the original event is restored
interactions = SchedulerTracing.unstable_getCurrent();
expect(interactions).toMatchInteractions([
{name: 'outer event', timestamp: 100},
]);
// Verify that a wrapped nested callback is properly traced
wrapperInnerIndirection();
expect(innerIndirectionTraced).toBe(true);
done();
});
});
describe('error handling', () => {
it('should reset state appropriately when an error occurs in a trace callback', done => {
advanceTimeBy(100);
SchedulerTracing.unstable_trace('outer event', currentTime, () => {
expect(() => {
SchedulerTracing.unstable_trace('inner event', currentTime, () => {
throw Error('intentional');
});
}).toThrow();
expect(SchedulerTracing.unstable_getCurrent()).toMatchInteractions([
{name: 'outer event', timestamp: 100},
]);
done();
});
});
it('should reset state appropriately when an error occurs in a wrapped callback', done => {
advanceTimeBy(100);
SchedulerTracing.unstable_trace('outer event', currentTime, () => {
let wrappedCallback;
SchedulerTracing.unstable_trace('inner event', currentTime, () => {
wrappedCallback = SchedulerTracing.unstable_wrap(() => {
throw Error('intentional');
});
});
expect(wrappedCallback).toThrow();
expect(SchedulerTracing.unstable_getCurrent()).toMatchInteractions([
{name: 'outer event', timestamp: 100},
]);
done();
});
});
});
describe('advanced integration', () => {
it('should return a unique threadID per request', () => {
expect(SchedulerTracing.unstable_getThreadID()).not.toBe(
SchedulerTracing.unstable_getThreadID(),
);
});
it('should expose the current set of interactions to be externally manipulated', () => {
SchedulerTracing.unstable_trace('outer event', currentTime, () => {
expect(SchedulerTracing.__interactionsRef.current).toBe(
SchedulerTracing.unstable_getCurrent(),
);
SchedulerTracing.__interactionsRef.current = new Set([
{name: 'override event'},
]);
expect(SchedulerTracing.unstable_getCurrent()).toMatchInteractions([
{name: 'override event'},
]);
});
});
it('should expose a subscriber ref to be externally manipulated', () => {
SchedulerTracing.unstable_trace('outer event', currentTime, () => {
expect(SchedulerTracing.__subscriberRef).toEqual({
current: null,
});
});
});
});
});
describe('enableSchedulerTracing disabled', () => {
beforeEach(() => loadModules({enableSchedulerTracing: false}));
it('should return the value of a traced function', () => {
expect(
SchedulerTracing.unstable_trace('arbitrary', currentTime, () => 123),
).toBe(123);
});
it('should return the value of a wrapped function', () => {
let wrapped;
SchedulerTracing.unstable_trace('arbitrary', currentTime, () => {
wrapped = SchedulerTracing.unstable_wrap(() => 123);
});
expect(wrapped()).toBe(123);
});
it('should return null for traced interactions', () => {
expect(SchedulerTracing.unstable_getCurrent()).toBe(null);
});
it('should execute traced callbacks', done => {
SchedulerTracing.unstable_trace('some event', currentTime, () => {
expect(SchedulerTracing.unstable_getCurrent()).toBe(null);
done();
});
});
it('should return the value of a clear function', () => {
expect(SchedulerTracing.unstable_clear(() => 123)).toBe(123);
});
it('should execute wrapped callbacks', done => {
const wrappedCallback = SchedulerTracing.unstable_wrap(() => {
expect(SchedulerTracing.unstable_getCurrent()).toBe(null);
done();
});
wrappedCallback();
});
describe('advanced integration', () => {
it('should not create unnecessary objects', () => {
expect(SchedulerTracing.__interactionsRef).toBe(null);
});
});
});
});
@@ -8,41 +8,41 @@
*/
'use strict';
describe('Tracking', () => {
let SchedulerTracking;
describe('Tracing', () => {
let SchedulerTracing;
beforeEach(() => {
jest.resetModules();
SchedulerTracking = require('schedule/tracking');
SchedulerTracing = require('schedule/tracing');
});
it('should return the value of a tracked function', () => {
expect(SchedulerTracking.unstable_track('arbitrary', 0, () => 123)).toBe(
it('should return the value of a traced function', () => {
expect(SchedulerTracing.unstable_trace('arbitrary', 0, () => 123)).toBe(
123,
);
});
it('should return the value of a wrapped function', () => {
let wrapped;
SchedulerTracking.unstable_track('arbitrary', 0, () => {
wrapped = SchedulerTracking.unstable_wrap(() => 123);
SchedulerTracing.unstable_trace('arbitrary', 0, () => {
wrapped = SchedulerTracing.unstable_wrap(() => 123);
});
expect(wrapped()).toBe(123);
});
it('should execute tracked callbacks', done => {
SchedulerTracking.unstable_track('some event', 0, () => {
it('should execute traced callbacks', done => {
SchedulerTracing.unstable_trace('some event', 0, () => {
done();
});
});
it('should return the value of a clear function', () => {
expect(SchedulerTracking.unstable_clear(() => 123)).toBe(123);
expect(SchedulerTracing.unstable_clear(() => 123)).toBe(123);
});
it('should execute wrapped callbacks', done => {
const wrappedCallback = SchedulerTracking.unstable_wrap(() => {
const wrappedCallback = SchedulerTracing.unstable_wrap(() => {
done();
});
@@ -8,20 +8,20 @@
*/
'use strict';
describe('TrackingSubscriptions', () => {
let SchedulerTracking;
describe('TracingSubscriptions', () => {
let SchedulerTracing;
let ReactFeatureFlags;
let currentTime;
let onInteractionScheduledWorkCompleted;
let onInteractionTracked;
let onInteractionTraced;
let onWorkCanceled;
let onWorkScheduled;
let onWorkStarted;
let onWorkStopped;
let throwInOnInteractionScheduledWorkCompleted;
let throwInOnInteractionTracked;
let throwInOnInteractionTraced;
let throwInOnWorkCanceled;
let throwInOnWorkScheduled;
let throwInOnWorkStarted;
@@ -33,19 +33,19 @@ describe('TrackingSubscriptions', () => {
const secondEvent = {id: 1, name: 'second', timestamp: 0};
const threadID = 123;
function loadModules({enableSchedulerTracking, autoSubscribe = true}) {
function loadModules({enableSchedulerTracing, autoSubscribe = true}) {
jest.resetModules();
jest.useFakeTimers();
currentTime = 0;
ReactFeatureFlags = require('shared/ReactFeatureFlags');
ReactFeatureFlags.enableSchedulerTracking = enableSchedulerTracking;
ReactFeatureFlags.enableSchedulerTracing = enableSchedulerTracing;
SchedulerTracking = require('schedule/tracking');
SchedulerTracing = require('schedule/tracing');
throwInOnInteractionScheduledWorkCompleted = false;
throwInOnInteractionTracked = false;
throwInOnInteractionTraced = false;
throwInOnWorkCanceled = false;
throwInOnWorkScheduled = false;
throwInOnWorkStarted = false;
@@ -56,9 +56,9 @@ describe('TrackingSubscriptions', () => {
throw Error('Expected error onInteractionScheduledWorkCompleted');
}
});
onInteractionTracked = jest.fn(() => {
if (throwInOnInteractionTracked) {
throw Error('Expected error onInteractionTracked');
onInteractionTraced = jest.fn(() => {
if (throwInOnInteractionTraced) {
throw Error('Expected error onInteractionTraced');
}
});
onWorkCanceled = jest.fn(() => {
@@ -84,7 +84,7 @@ describe('TrackingSubscriptions', () => {
firstSubscriber = {
onInteractionScheduledWorkCompleted,
onInteractionTracked,
onInteractionTraced,
onWorkCanceled,
onWorkScheduled,
onWorkStarted,
@@ -93,7 +93,7 @@ describe('TrackingSubscriptions', () => {
secondSubscriber = {
onInteractionScheduledWorkCompleted: jest.fn(),
onInteractionTracked: jest.fn(),
onInteractionTraced: jest.fn(),
onWorkCanceled: jest.fn(),
onWorkScheduled: jest.fn(),
onWorkStarted: jest.fn(),
@@ -101,49 +101,49 @@ describe('TrackingSubscriptions', () => {
};
if (autoSubscribe) {
SchedulerTracking.unstable_subscribe(firstSubscriber);
SchedulerTracking.unstable_subscribe(secondSubscriber);
SchedulerTracing.unstable_subscribe(firstSubscriber);
SchedulerTracing.unstable_subscribe(secondSubscriber);
}
}
describe('enabled', () => {
beforeEach(() => loadModules({enableSchedulerTracking: true}));
beforeEach(() => loadModules({enableSchedulerTracing: true}));
it('should lazily subscribe to tracking and unsubscribe again if there are no external subscribers', () => {
loadModules({enableSchedulerTracking: true, autoSubscribe: false});
it('should lazily subscribe to tracing and unsubscribe again if there are no external subscribers', () => {
loadModules({enableSchedulerTracing: true, autoSubscribe: false});
expect(SchedulerTracking.__subscriberRef.current).toBe(null);
SchedulerTracking.unstable_subscribe(firstSubscriber);
expect(SchedulerTracking.__subscriberRef.current).toBeDefined();
SchedulerTracking.unstable_subscribe(secondSubscriber);
expect(SchedulerTracking.__subscriberRef.current).toBeDefined();
SchedulerTracking.unstable_unsubscribe(secondSubscriber);
expect(SchedulerTracking.__subscriberRef.current).toBeDefined();
SchedulerTracking.unstable_unsubscribe(firstSubscriber);
expect(SchedulerTracking.__subscriberRef.current).toBe(null);
expect(SchedulerTracing.__subscriberRef.current).toBe(null);
SchedulerTracing.unstable_subscribe(firstSubscriber);
expect(SchedulerTracing.__subscriberRef.current).toBeDefined();
SchedulerTracing.unstable_subscribe(secondSubscriber);
expect(SchedulerTracing.__subscriberRef.current).toBeDefined();
SchedulerTracing.unstable_unsubscribe(secondSubscriber);
expect(SchedulerTracing.__subscriberRef.current).toBeDefined();
SchedulerTracing.unstable_unsubscribe(firstSubscriber);
expect(SchedulerTracing.__subscriberRef.current).toBe(null);
});
describe('error handling', () => {
it('should cover onInteractionTracked/onWorkStarted within', done => {
SchedulerTracking.unstable_track(firstEvent.name, currentTime, () => {
it('should cover onInteractionTraced/onWorkStarted within', done => {
SchedulerTracing.unstable_trace(firstEvent.name, currentTime, () => {
const mock = jest.fn();
// It should call the callback before re-throwing
throwInOnInteractionTracked = true;
throwInOnInteractionTraced = true;
expect(() =>
SchedulerTracking.unstable_track(
SchedulerTracing.unstable_trace(
secondEvent.name,
currentTime,
mock,
threadID,
),
).toThrow('Expected error onInteractionTracked');
throwInOnInteractionTracked = false;
).toThrow('Expected error onInteractionTraced');
throwInOnInteractionTraced = false;
expect(mock).toHaveBeenCalledTimes(1);
throwInOnWorkStarted = true;
expect(() =>
SchedulerTracking.unstable_track(
SchedulerTracing.unstable_trace(
secondEvent.name,
currentTime,
mock,
@@ -153,32 +153,30 @@ describe('TrackingSubscriptions', () => {
expect(mock).toHaveBeenCalledTimes(2);
// It should restore the previous/outer interactions
expect(SchedulerTracking.unstable_getCurrent()).toMatchInteractions([
expect(SchedulerTracing.unstable_getCurrent()).toMatchInteractions([
firstEvent,
]);
// It should call other subscribers despite the earlier error
expect(secondSubscriber.onInteractionTracked).toHaveBeenCalledTimes(
3,
);
expect(secondSubscriber.onInteractionTraced).toHaveBeenCalledTimes(3);
expect(secondSubscriber.onWorkStarted).toHaveBeenCalledTimes(3);
done();
});
});
it('should cover onWorkStopped within track', done => {
SchedulerTracking.unstable_track(firstEvent.name, currentTime, () => {
it('should cover onWorkStopped within trace', done => {
SchedulerTracing.unstable_trace(firstEvent.name, currentTime, () => {
let innerInteraction;
const mock = jest.fn(() => {
innerInteraction = Array.from(
SchedulerTracking.unstable_getCurrent(),
SchedulerTracing.unstable_getCurrent(),
)[1];
});
throwInOnWorkStopped = true;
expect(() =>
SchedulerTracking.unstable_track(
SchedulerTracing.unstable_trace(
secondEvent.name,
currentTime,
mock,
@@ -187,7 +185,7 @@ describe('TrackingSubscriptions', () => {
throwInOnWorkStopped = false;
// It should restore the previous/outer interactions
expect(SchedulerTracking.unstable_getCurrent()).toMatchInteractions([
expect(SchedulerTracing.unstable_getCurrent()).toMatchInteractions([
firstEvent,
]);
@@ -201,13 +199,13 @@ describe('TrackingSubscriptions', () => {
});
});
it('should cover onInteractionScheduledWorkCompleted within track', done => {
SchedulerTracking.unstable_track(firstEvent.name, currentTime, () => {
it('should cover onInteractionScheduledWorkCompleted within trace', done => {
SchedulerTracing.unstable_trace(firstEvent.name, currentTime, () => {
const mock = jest.fn();
throwInOnInteractionScheduledWorkCompleted = true;
expect(() =>
SchedulerTracking.unstable_track(
SchedulerTracing.unstable_trace(
secondEvent.name,
currentTime,
mock,
@@ -216,7 +214,7 @@ describe('TrackingSubscriptions', () => {
throwInOnInteractionScheduledWorkCompleted = false;
// It should restore the previous/outer interactions
expect(SchedulerTracking.unstable_getCurrent()).toMatchInteractions([
expect(SchedulerTracing.unstable_getCurrent()).toMatchInteractions([
firstEvent,
]);
@@ -229,12 +227,12 @@ describe('TrackingSubscriptions', () => {
});
});
it('should cover the callback within track', done => {
it('should cover the callback within trace', done => {
expect(onWorkStarted).not.toHaveBeenCalled();
expect(onWorkStopped).not.toHaveBeenCalled();
expect(() => {
SchedulerTracking.unstable_track(firstEvent.name, currentTime, () => {
SchedulerTracing.unstable_trace(firstEvent.name, currentTime, () => {
throw Error('Expected error callback');
});
}).toThrow('Expected error callback');
@@ -246,14 +244,14 @@ describe('TrackingSubscriptions', () => {
});
it('should cover onWorkScheduled within wrap', done => {
SchedulerTracking.unstable_track(firstEvent.name, currentTime, () => {
SchedulerTracing.unstable_trace(firstEvent.name, currentTime, () => {
const interaction = Array.from(
SchedulerTracking.unstable_getCurrent(),
SchedulerTracing.unstable_getCurrent(),
)[0];
const beforeCount = interaction.__count;
throwInOnWorkScheduled = true;
expect(() => SchedulerTracking.unstable_wrap(() => {})).toThrow(
expect(() => SchedulerTracing.unstable_wrap(() => {})).toThrow(
'Expected error onWorkScheduled',
);
@@ -270,9 +268,9 @@ describe('TrackingSubscriptions', () => {
it('should cover onWorkStarted within wrap', () => {
const mock = jest.fn();
let interaction, wrapped;
SchedulerTracking.unstable_track(firstEvent.name, currentTime, () => {
interaction = Array.from(SchedulerTracking.unstable_getCurrent())[0];
wrapped = SchedulerTracking.unstable_wrap(mock);
SchedulerTracing.unstable_trace(firstEvent.name, currentTime, () => {
interaction = Array.from(SchedulerTracing.unstable_getCurrent())[0];
wrapped = SchedulerTracing.unstable_wrap(mock);
});
expect(interaction.__count).toBe(1);
@@ -290,30 +288,26 @@ describe('TrackingSubscriptions', () => {
});
it('should cover onWorkStopped within wrap', done => {
SchedulerTracking.unstable_track(firstEvent.name, currentTime, () => {
SchedulerTracing.unstable_trace(firstEvent.name, currentTime, () => {
const outerInteraction = Array.from(
SchedulerTracking.unstable_getCurrent(),
SchedulerTracing.unstable_getCurrent(),
)[0];
expect(outerInteraction.__count).toBe(1);
let wrapped;
let innerInteraction;
SchedulerTracking.unstable_track(
secondEvent.name,
currentTime,
() => {
innerInteraction = Array.from(
SchedulerTracking.unstable_getCurrent(),
)[1];
expect(outerInteraction.__count).toBe(1);
expect(innerInteraction.__count).toBe(1);
SchedulerTracing.unstable_trace(secondEvent.name, currentTime, () => {
innerInteraction = Array.from(
SchedulerTracing.unstable_getCurrent(),
)[1];
expect(outerInteraction.__count).toBe(1);
expect(innerInteraction.__count).toBe(1);
wrapped = SchedulerTracking.unstable_wrap(jest.fn());
expect(outerInteraction.__count).toBe(2);
expect(innerInteraction.__count).toBe(2);
},
);
wrapped = SchedulerTracing.unstable_wrap(jest.fn());
expect(outerInteraction.__count).toBe(2);
expect(innerInteraction.__count).toBe(2);
});
expect(outerInteraction.__count).toBe(2);
expect(innerInteraction.__count).toBe(1);
@@ -323,7 +317,7 @@ describe('TrackingSubscriptions', () => {
throwInOnWorkStopped = false;
// It should restore the previous interactions
expect(SchedulerTracking.unstable_getCurrent()).toMatchInteractions([
expect(SchedulerTracing.unstable_getCurrent()).toMatchInteractions([
outerInteraction,
]);
@@ -343,9 +337,9 @@ describe('TrackingSubscriptions', () => {
let wrapped;
let interaction;
SchedulerTracking.unstable_track(firstEvent.name, currentTime, () => {
interaction = Array.from(SchedulerTracking.unstable_getCurrent())[0];
wrapped = SchedulerTracking.unstable_wrap(() => {
SchedulerTracing.unstable_trace(firstEvent.name, currentTime, () => {
interaction = Array.from(SchedulerTracing.unstable_getCurrent())[0];
wrapped = SchedulerTracing.unstable_wrap(() => {
throw Error('Expected error wrap');
});
});
@@ -364,9 +358,9 @@ describe('TrackingSubscriptions', () => {
it('should cover onWorkCanceled within wrap', () => {
let interaction, wrapped;
SchedulerTracking.unstable_track(firstEvent.name, currentTime, () => {
interaction = Array.from(SchedulerTracking.unstable_getCurrent())[0];
wrapped = SchedulerTracking.unstable_wrap(jest.fn());
SchedulerTracing.unstable_trace(firstEvent.name, currentTime, () => {
interaction = Array.from(SchedulerTracing.unstable_getCurrent())[0];
wrapped = SchedulerTracing.unstable_wrap(jest.fn());
});
expect(interaction.__count).toBe(1);
@@ -386,16 +380,16 @@ describe('TrackingSubscriptions', () => {
});
});
it('calls lifecycle methods for track', () => {
expect(onInteractionTracked).not.toHaveBeenCalled();
it('calls lifecycle methods for trace', () => {
expect(onInteractionTraced).not.toHaveBeenCalled();
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();
SchedulerTracking.unstable_track(
SchedulerTracing.unstable_trace(
firstEvent.name,
currentTime,
() => {
expect(onInteractionTracked).toHaveBeenCalledTimes(1);
expect(onInteractionTracked).toHaveBeenLastNotifiedOfInteraction(
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
expect(onInteractionTraced).toHaveBeenLastNotifiedOfInteraction(
firstEvent,
);
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();
@@ -406,12 +400,12 @@ describe('TrackingSubscriptions', () => {
);
expect(onWorkStopped).not.toHaveBeenCalled();
SchedulerTracking.unstable_track(
SchedulerTracing.unstable_trace(
secondEvent.name,
currentTime,
() => {
expect(onInteractionTracked).toHaveBeenCalledTimes(2);
expect(onInteractionTracked).toHaveBeenLastNotifiedOfInteraction(
expect(onInteractionTraced).toHaveBeenCalledTimes(2);
expect(onInteractionTraced).toHaveBeenLastNotifiedOfInteraction(
secondEvent,
);
expect(
@@ -458,19 +452,19 @@ describe('TrackingSubscriptions', () => {
const unwrapped = jest.fn();
let wrapped;
SchedulerTracking.unstable_track(firstEvent.name, currentTime, () => {
expect(onInteractionTracked).toHaveBeenCalledTimes(1);
expect(onInteractionTracked).toHaveBeenLastNotifiedOfInteraction(
SchedulerTracing.unstable_trace(firstEvent.name, currentTime, () => {
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
expect(onInteractionTraced).toHaveBeenLastNotifiedOfInteraction(
firstEvent,
);
SchedulerTracking.unstable_track(secondEvent.name, currentTime, () => {
expect(onInteractionTracked).toHaveBeenCalledTimes(2);
expect(onInteractionTracked).toHaveBeenLastNotifiedOfInteraction(
SchedulerTracing.unstable_trace(secondEvent.name, currentTime, () => {
expect(onInteractionTraced).toHaveBeenCalledTimes(2);
expect(onInteractionTraced).toHaveBeenLastNotifiedOfInteraction(
secondEvent,
);
wrapped = SchedulerTracking.unstable_wrap(unwrapped, threadID);
wrapped = SchedulerTracing.unstable_wrap(unwrapped, threadID);
expect(onWorkScheduled).toHaveBeenCalledTimes(1);
expect(onWorkScheduled).toHaveBeenLastNotifiedOfWork(
new Set([firstEvent, secondEvent]),
@@ -479,7 +473,7 @@ describe('TrackingSubscriptions', () => {
});
});
expect(onInteractionTracked).toHaveBeenCalledTimes(2);
expect(onInteractionTraced).toHaveBeenCalledTimes(2);
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();
wrapped();
@@ -510,14 +504,14 @@ describe('TrackingSubscriptions', () => {
const fnOne = jest.fn();
const fnTwo = jest.fn();
let wrappedOne, wrappedTwo;
SchedulerTracking.unstable_track(firstEvent.name, currentTime, () => {
wrappedOne = SchedulerTracking.unstable_wrap(fnOne, threadID);
SchedulerTracking.unstable_track(secondEvent.name, currentTime, () => {
wrappedTwo = SchedulerTracking.unstable_wrap(fnTwo, threadID);
SchedulerTracing.unstable_trace(firstEvent.name, currentTime, () => {
wrappedOne = SchedulerTracing.unstable_wrap(fnOne, threadID);
SchedulerTracing.unstable_trace(secondEvent.name, currentTime, () => {
wrappedTwo = SchedulerTracing.unstable_wrap(fnTwo, threadID);
});
});
expect(onInteractionTracked).toHaveBeenCalledTimes(2);
expect(onInteractionTraced).toHaveBeenCalledTimes(2);
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();
expect(onWorkCanceled).not.toHaveBeenCalled();
expect(onWorkStarted).toHaveBeenCalledTimes(2);
@@ -553,25 +547,25 @@ describe('TrackingSubscriptions', () => {
it('should not end an interaction twice if wrap is used to schedule follow up work within another wrap', () => {
const fnOne = jest.fn(() => {
wrappedTwo = SchedulerTracking.unstable_wrap(fnTwo, threadID);
wrappedTwo = SchedulerTracing.unstable_wrap(fnTwo, threadID);
});
const fnTwo = jest.fn();
let wrappedOne, wrappedTwo;
SchedulerTracking.unstable_track(firstEvent.name, currentTime, () => {
wrappedOne = SchedulerTracking.unstable_wrap(fnOne, threadID);
SchedulerTracing.unstable_trace(firstEvent.name, currentTime, () => {
wrappedOne = SchedulerTracing.unstable_wrap(fnOne, threadID);
});
expect(onInteractionTracked).toHaveBeenCalledTimes(1);
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();
wrappedOne();
expect(onInteractionTracked).toHaveBeenCalledTimes(1);
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();
wrappedTwo();
expect(onInteractionTracked).toHaveBeenCalledTimes(1);
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1);
expect(
onInteractionScheduledWorkCompleted,
@@ -582,29 +576,29 @@ describe('TrackingSubscriptions', () => {
const unwrappedOne = jest.fn();
const unwrappedTwo = jest.fn();
let wrappedOne, wrappedTwo;
SchedulerTracking.unstable_track(firstEvent.name, currentTime, () => {
wrappedOne = SchedulerTracking.unstable_wrap(unwrappedOne, threadID);
wrappedTwo = SchedulerTracking.unstable_wrap(unwrappedTwo, threadID);
SchedulerTracing.unstable_trace(firstEvent.name, currentTime, () => {
wrappedOne = SchedulerTracing.unstable_wrap(unwrappedOne, threadID);
wrappedTwo = SchedulerTracing.unstable_wrap(unwrappedTwo, threadID);
});
expect(onInteractionTracked).toHaveBeenCalledTimes(1);
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();
wrappedOne();
expect(unwrappedOne).toHaveBeenCalledTimes(1);
expect(onInteractionTracked).toHaveBeenCalledTimes(1);
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();
wrappedOne();
expect(unwrappedOne).toHaveBeenCalledTimes(2);
expect(onInteractionTracked).toHaveBeenCalledTimes(1);
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();
wrappedTwo();
expect(onInteractionTracked).toHaveBeenCalledTimes(1);
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1);
expect(
onInteractionScheduledWorkCompleted,
@@ -612,15 +606,15 @@ describe('TrackingSubscriptions', () => {
});
it('should unsubscribe', () => {
SchedulerTracking.unstable_unsubscribe(firstSubscriber);
SchedulerTracking.unstable_track(firstEvent.name, currentTime, () => {});
SchedulerTracing.unstable_unsubscribe(firstSubscriber);
SchedulerTracing.unstable_trace(firstEvent.name, currentTime, () => {});
expect(onInteractionTracked).not.toHaveBeenCalled();
expect(onInteractionTraced).not.toHaveBeenCalled();
});
});
describe('disabled', () => {
beforeEach(() => loadModules({enableSchedulerTracking: false}));
beforeEach(() => loadModules({enableSchedulerTracing: false}));
// TODO
});
@@ -1,375 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment node
*/
'use strict';
describe('Tracking', () => {
let SchedulerTracking;
let ReactFeatureFlags;
let advanceTimeBy;
let currentTime;
function loadModules({enableSchedulerTracking}) {
jest.resetModules();
jest.useFakeTimers();
currentTime = 0;
Date.now = jest.fn().mockImplementation(() => currentTime);
advanceTimeBy = amount => {
currentTime += amount;
};
ReactFeatureFlags = require('shared/ReactFeatureFlags');
ReactFeatureFlags.enableSchedulerTracking = enableSchedulerTracking;
SchedulerTracking = require('schedule/tracking');
}
describe('enableSchedulerTracking enabled', () => {
beforeEach(() => loadModules({enableSchedulerTracking: true}));
it('should return the value of a tracked function', () => {
expect(
SchedulerTracking.unstable_track('arbitrary', currentTime, () => 123),
).toBe(123);
});
it('should return the value of a clear function', () => {
expect(SchedulerTracking.unstable_clear(() => 123)).toBe(123);
});
it('should return the value of a wrapped function', () => {
let wrapped;
SchedulerTracking.unstable_track('arbitrary', currentTime, () => {
wrapped = SchedulerTracking.unstable_wrap(() => 123);
});
expect(wrapped()).toBe(123);
});
it('should pass arguments through to a wrapped function', done => {
let wrapped;
SchedulerTracking.unstable_track('arbitrary', currentTime, () => {
wrapped = SchedulerTracking.unstable_wrap((param1, param2) => {
expect(param1).toBe('foo');
expect(param2).toBe('bar');
done();
});
});
wrapped('foo', 'bar');
});
it('should return an empty set when outside of a tracked event', () => {
expect(SchedulerTracking.unstable_getCurrent()).toContainNoInteractions();
});
it('should report the tracked interaction from within the track callback', done => {
advanceTimeBy(100);
SchedulerTracking.unstable_track('some event', currentTime, () => {
const interactions = SchedulerTracking.unstable_getCurrent();
expect(interactions).toMatchInteractions([
{name: 'some event', timestamp: 100},
]);
done();
});
});
it('should report the tracked interaction from within wrapped callbacks', done => {
let wrappedIndirection;
function indirection() {
const interactions = SchedulerTracking.unstable_getCurrent();
expect(interactions).toMatchInteractions([
{name: 'some event', timestamp: 100},
]);
done();
}
advanceTimeBy(100);
SchedulerTracking.unstable_track('some event', currentTime, () => {
wrappedIndirection = SchedulerTracking.unstable_wrap(indirection);
});
advanceTimeBy(50);
wrappedIndirection();
});
it('should clear the interaction stack for tracked callbacks', () => {
let innerTestReached = false;
SchedulerTracking.unstable_track('outer event', currentTime, () => {
expect(SchedulerTracking.unstable_getCurrent()).toMatchInteractions([
{name: 'outer event'},
]);
SchedulerTracking.unstable_clear(() => {
expect(SchedulerTracking.unstable_getCurrent()).toMatchInteractions(
[],
);
SchedulerTracking.unstable_track('inner event', currentTime, () => {
expect(SchedulerTracking.unstable_getCurrent()).toMatchInteractions(
[{name: 'inner event'}],
);
innerTestReached = true;
});
});
expect(SchedulerTracking.unstable_getCurrent()).toMatchInteractions([
{name: 'outer event'},
]);
});
expect(innerTestReached).toBe(true);
});
it('should clear the interaction stack for wrapped callbacks', () => {
let innerTestReached = false;
let wrappedIndirection;
const indirection = jest.fn(() => {
expect(SchedulerTracking.unstable_getCurrent()).toMatchInteractions([
{name: 'outer event'},
]);
SchedulerTracking.unstable_clear(() => {
expect(SchedulerTracking.unstable_getCurrent()).toMatchInteractions(
[],
);
SchedulerTracking.unstable_track('inner event', currentTime, () => {
expect(SchedulerTracking.unstable_getCurrent()).toMatchInteractions(
[{name: 'inner event'}],
);
innerTestReached = true;
});
});
expect(SchedulerTracking.unstable_getCurrent()).toMatchInteractions([
{name: 'outer event'},
]);
});
SchedulerTracking.unstable_track('outer event', currentTime, () => {
wrappedIndirection = SchedulerTracking.unstable_wrap(indirection);
});
wrappedIndirection();
expect(innerTestReached).toBe(true);
});
it('should support nested tracked events', done => {
advanceTimeBy(100);
let innerIndirectionTracked = false;
let outerIndirectionTracked = false;
function innerIndirection() {
const interactions = SchedulerTracking.unstable_getCurrent();
expect(interactions).toMatchInteractions([
{name: 'outer event', timestamp: 100},
{name: 'inner event', timestamp: 150},
]);
innerIndirectionTracked = true;
}
function outerIndirection() {
const interactions = SchedulerTracking.unstable_getCurrent();
expect(interactions).toMatchInteractions([
{name: 'outer event', timestamp: 100},
]);
outerIndirectionTracked = true;
}
SchedulerTracking.unstable_track('outer event', currentTime, () => {
// Verify the current tracked event
let interactions = SchedulerTracking.unstable_getCurrent();
expect(interactions).toMatchInteractions([
{name: 'outer event', timestamp: 100},
]);
advanceTimeBy(50);
const wrapperOuterIndirection = SchedulerTracking.unstable_wrap(
outerIndirection,
);
let wrapperInnerIndirection;
let innerEventTracked = false;
// Verify that a nested event is properly tracked
SchedulerTracking.unstable_track('inner event', currentTime, () => {
interactions = SchedulerTracking.unstable_getCurrent();
expect(interactions).toMatchInteractions([
{name: 'outer event', timestamp: 100},
{name: 'inner event', timestamp: 150},
]);
// Verify that a wrapped outer callback is properly tracked
wrapperOuterIndirection();
expect(outerIndirectionTracked).toBe(true);
wrapperInnerIndirection = SchedulerTracking.unstable_wrap(
innerIndirection,
);
innerEventTracked = true;
});
expect(innerEventTracked).toBe(true);
// Verify that the original event is restored
interactions = SchedulerTracking.unstable_getCurrent();
expect(interactions).toMatchInteractions([
{name: 'outer event', timestamp: 100},
]);
// Verify that a wrapped nested callback is properly tracked
wrapperInnerIndirection();
expect(innerIndirectionTracked).toBe(true);
done();
});
});
describe('error handling', () => {
it('should reset state appropriately when an error occurs in a track callback', done => {
advanceTimeBy(100);
SchedulerTracking.unstable_track('outer event', currentTime, () => {
expect(() => {
SchedulerTracking.unstable_track('inner event', currentTime, () => {
throw Error('intentional');
});
}).toThrow();
expect(SchedulerTracking.unstable_getCurrent()).toMatchInteractions([
{name: 'outer event', timestamp: 100},
]);
done();
});
});
it('should reset state appropriately when an error occurs in a wrapped callback', done => {
advanceTimeBy(100);
SchedulerTracking.unstable_track('outer event', currentTime, () => {
let wrappedCallback;
SchedulerTracking.unstable_track('inner event', currentTime, () => {
wrappedCallback = SchedulerTracking.unstable_wrap(() => {
throw Error('intentional');
});
});
expect(wrappedCallback).toThrow();
expect(SchedulerTracking.unstable_getCurrent()).toMatchInteractions([
{name: 'outer event', timestamp: 100},
]);
done();
});
});
});
describe('advanced integration', () => {
it('should return a unique threadID per request', () => {
expect(SchedulerTracking.unstable_getThreadID()).not.toBe(
SchedulerTracking.unstable_getThreadID(),
);
});
it('should expose the current set of interactions to be externally manipulated', () => {
SchedulerTracking.unstable_track('outer event', currentTime, () => {
expect(SchedulerTracking.__interactionsRef.current).toBe(
SchedulerTracking.unstable_getCurrent(),
);
SchedulerTracking.__interactionsRef.current = new Set([
{name: 'override event'},
]);
expect(SchedulerTracking.unstable_getCurrent()).toMatchInteractions([
{name: 'override event'},
]);
});
});
it('should expose a subscriber ref to be externally manipulated', () => {
SchedulerTracking.unstable_track('outer event', currentTime, () => {
expect(SchedulerTracking.__subscriberRef).toEqual({
current: null,
});
});
});
});
});
describe('enableSchedulerTracking disabled', () => {
beforeEach(() => loadModules({enableSchedulerTracking: false}));
it('should return the value of a tracked function', () => {
expect(
SchedulerTracking.unstable_track('arbitrary', currentTime, () => 123),
).toBe(123);
});
it('should return the value of a wrapped function', () => {
let wrapped;
SchedulerTracking.unstable_track('arbitrary', currentTime, () => {
wrapped = SchedulerTracking.unstable_wrap(() => 123);
});
expect(wrapped()).toBe(123);
});
it('should return null for tracked interactions', () => {
expect(SchedulerTracking.unstable_getCurrent()).toBe(null);
});
it('should execute tracked callbacks', done => {
SchedulerTracking.unstable_track('some event', currentTime, () => {
expect(SchedulerTracking.unstable_getCurrent()).toBe(null);
done();
});
});
it('should return the value of a clear function', () => {
expect(SchedulerTracking.unstable_clear(() => 123)).toBe(123);
});
it('should execute wrapped callbacks', done => {
const wrappedCallback = SchedulerTracking.unstable_wrap(() => {
expect(SchedulerTracking.unstable_getCurrent()).toBe(null);
done();
});
wrappedCallback();
});
describe('advanced integration', () => {
it('should not create unnecessary objects', () => {
expect(SchedulerTracking.__interactionsRef).toBe(null);
});
});
});
});
@@ -9,5 +9,5 @@
'use strict';
export * from './src/Tracking';
export * from './src/TrackingSubscriptions';
export * from './src/Tracing';
export * from './src/TracingSubscriptions';
+2 -2
View File
@@ -37,8 +37,8 @@ export const warnAboutLegacyContextAPI = false;
// Gather advanced timing metrics for Profiler subtrees.
export const enableProfilerTimer = __PROFILE__;
// Track which interactions trigger each commit.
export const enableSchedulerTracking = __PROFILE__;
// Trace which interactions trigger each commit.
export const enableSchedulerTracing = __PROFILE__;
// Only used in www builds.
export const enableSuspenseServerRenderer = false;
@@ -21,7 +21,7 @@ export const warnAboutDeprecatedLifecycles = false;
export const warnAboutLegacyContextAPI = __DEV__;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
export const enableProfilerTimer = __PROFILE__;
export const enableSchedulerTracking = __PROFILE__;
export const enableSchedulerTracing = __PROFILE__;
export const enableSuspenseServerRenderer = false;
export const disableInputAttributeSyncing = false;
@@ -21,7 +21,7 @@ export const warnAboutDeprecatedLifecycles = false;
export const warnAboutLegacyContextAPI = false;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
export const enableProfilerTimer = __PROFILE__;
export const enableSchedulerTracking = __PROFILE__;
export const enableSchedulerTracing = __PROFILE__;
export const enableSuspenseServerRenderer = false;
export const disableInputAttributeSyncing = false;
@@ -27,7 +27,7 @@ export const {
export const enableUserTimingAPI = __DEV__;
export const warnAboutLegacyContextAPI = __DEV__;
export const enableProfilerTimer = __PROFILE__;
export const enableSchedulerTracking = __PROFILE__;
export const enableSchedulerTracing = __PROFILE__;
export const enableSuspenseServerRenderer = false;
// Only used in www builds.
@@ -21,7 +21,7 @@ export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
export const warnAboutDeprecatedLifecycles = false;
export const warnAboutLegacyContextAPI = false;
export const enableProfilerTimer = __PROFILE__;
export const enableSchedulerTracking = __PROFILE__;
export const enableSchedulerTracing = __PROFILE__;
export const enableSuspenseServerRenderer = false;
export const disableInputAttributeSyncing = false;
@@ -21,7 +21,7 @@ export const warnAboutDeprecatedLifecycles = false;
export const warnAboutLegacyContextAPI = false;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
export const enableProfilerTimer = __PROFILE__;
export const enableSchedulerTracking = __PROFILE__;
export const enableSchedulerTracing = __PROFILE__;
export const enableSuspenseServerRenderer = false;
export const disableInputAttributeSyncing = false;
@@ -21,7 +21,7 @@ export const warnAboutDeprecatedLifecycles = false;
export const warnAboutLegacyContextAPI = false;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
export const enableProfilerTimer = false;
export const enableSchedulerTracking = false;
export const enableSchedulerTracing = false;
export const enableSuspenseServerRenderer = false;
export const disableInputAttributeSyncing = false;
@@ -21,7 +21,7 @@ export const warnAboutDeprecatedLifecycles = false;
export const warnAboutLegacyContextAPI = false;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
export const enableProfilerTimer = false;
export const enableSchedulerTracking = false;
export const enableSchedulerTracing = false;
export const enableSuspenseServerRenderer = false;
// Only used in www builds.
@@ -34,7 +34,7 @@ export const warnAboutLegacyContextAPI = __DEV__;
export let enableUserTimingAPI = __DEV__;
export const enableProfilerTimer = __PROFILE__;
export const enableSchedulerTracking = __PROFILE__;
export const enableSchedulerTracing = __PROFILE__;
let refCount = 0;
export function addUserTimingListener() {
@@ -18,10 +18,10 @@ const {
unstable_getCurrent,
unstable_getThreadID,
unstable_subscribe,
unstable_track,
unstable_trace,
unstable_unsubscribe,
unstable_wrap,
} = ReactInternals.ScheduleTracking;
} = ReactInternals.ScheduleTracing;
export {
__interactionsRef,
@@ -30,7 +30,7 @@ export {
unstable_getCurrent,
unstable_getThreadID,
unstable_subscribe,
unstable_track,
unstable_trace,
unstable_unsubscribe,
unstable_wrap,
};
+1 -1
View File
@@ -44,7 +44,7 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
}
expect.extend({
...require('./matchers/interactionTracking'),
...require('./matchers/interactionTracing'),
...require('./matchers/toWarnDev'),
...require('./matchers/testRenderer'),
});
@@ -46,7 +46,7 @@ global.spyOnProd = function(...args) {
};
expect.extend({
...require('../matchers/interactionTracking'),
...require('../matchers/interactionTracing'),
...require('../matchers/toWarnDev'),
...require('../matchers/testRenderer'),
});
+3 -3
View File
@@ -391,7 +391,7 @@ const bundles = [
},
{
label: 'schedule-tracking',
label: 'schedule-tracing',
bundleTypes: [
FB_WWW_DEV,
FB_WWW_PROD,
@@ -401,8 +401,8 @@ const bundles = [
NODE_PROFILING,
],
moduleType: ISOMORPHIC,
entry: 'schedule/tracking',
global: 'ScheduleTracking',
entry: 'schedule/tracing',
global: 'ScheduleTracing',
externals: [],
},
];
+2 -2
View File
@@ -132,7 +132,7 @@ const forks = Object.freeze({
}
},
'schedule/tracking': (bundleType, entry, dependencies) => {
'schedule/tracing': (bundleType, entry, dependencies) => {
switch (bundleType) {
case UMD_DEV:
case UMD_PROD:
@@ -143,7 +143,7 @@ const forks = Object.freeze({
}
// Optimization: for UMDs, use the API that is already a part of the React
// package instead of requiring it to be loaded via a separate <script> tag
return 'shared/forks/ScheduleTracking.umd.js';
return 'shared/forks/ScheduleTracing.umd.js';
default:
// For other bundles, use the shared NPM package.
return null;
+2 -2
View File
@@ -15,7 +15,7 @@ const importSideEffects = Object.freeze({
'prop-types/checkPropTypes': HAS_NO_SIDE_EFFECTS_ON_IMPORT,
deepFreezeAndThrowOnMutationInDev: HAS_NO_SIDE_EFFECTS_ON_IMPORT,
schedule: HAS_NO_SIDE_EFFECTS_ON_IMPORT,
'schedule/tracking': HAS_NO_SIDE_EFFECTS_ON_IMPORT,
'schedule/tracing': HAS_NO_SIDE_EFFECTS_ON_IMPORT,
});
// Bundles exporting globals that other modules rely on.
@@ -23,7 +23,7 @@ const knownGlobals = Object.freeze({
react: 'React',
'react-dom': 'ReactDOM',
schedule: 'Schedule',
'schedule/tracking': 'ScheduleTracking',
'schedule/tracing': 'ScheduleTracing',
});
// Given ['react'] in bundle externals, returns { 'react': 'React' }.