Skip to content

Commit f1561e9

Browse files
author
Brian Vaughn
authored
Merge pull request #274 from bvaughn/commit-priority-level
Show commit priority levels in Profiler UI (if available)
2 parents 146fd2a + d440380 commit f1561e9

File tree

14 files changed

+209
-51
lines changed

14 files changed

+209
-51
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,16 @@
132132
"opener": "^1.5.1",
133133
"prettier": "^1.16.4",
134134
"prop-types": "^15.6.2",
135-
"react": "^0.0.0-6da04b5d8",
135+
"react": "^0.0.0-50b50c26f",
136136
"react-color": "^2.11.7",
137-
"react-dom": "^0.0.0-6da04b5d8",
138-
"react-is": "^0.0.0-6da04b5d8",
139-
"react-test-renderer": "^0.0.0-6da04b5d8",
137+
"react-dom": "^0.0.0-50b50c26f",
138+
"react-is": "^0.0.0-50b50c26f",
139+
"react-test-renderer": "^0.0.0-50b50c26f",
140140
"react-virtualized-auto-sizer": "^1.0.2",
141141
"react-window": "^1.8.0",
142142
"request-promise": "^4.2.4",
143143
"rimraf": "^2.6.3",
144-
"scheduler": "^0.0.0-6da04b5d8",
144+
"scheduler": "^0.0.0-50b50c26f",
145145
"semver": "^5.5.1",
146146
"style-loader": "^0.23.1",
147147
"web-ext": "^3.0.0",

shells/dev/app/ElementTypes/index.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import React, {
66
lazy,
77
memo,
88
Component,
9-
// $FlowFixMe Flow thinks ConcurrentMode is stable
10-
unstable_ConcurrentMode as ConcurrentMode,
119
Fragment,
1210
// $FlowFixMe Flow doesn't know about the Profiler import yet
1311
Profiler,
@@ -48,15 +46,13 @@ export default function ElementTypes() {
4846
<Context.Consumer>{value => null}</Context.Consumer>
4947
</Context.Provider>
5048
<StrictMode>
51-
<ConcurrentMode>
52-
<Suspense fallback={<div>Loading...</div>}>
53-
<ClassComponent />
54-
<FunctionComponent />
55-
<MemoFunctionComponent />
56-
<ForwardRefComponent />
57-
<LazyComponent />
58-
</Suspense>
59-
</ConcurrentMode>
49+
<Suspense fallback={<div>Loading...</div>}>
50+
<ClassComponent />
51+
<FunctionComponent />
52+
<MemoFunctionComponent />
53+
<ForwardRefComponent />
54+
<LazyComponent />
55+
</Suspense>
6056
</StrictMode>
6157
</Fragment>
6258
</Profiler>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// @flow
2+
3+
import React, { Fragment, useCallback, useState } from 'react';
4+
import {
5+
unstable_IdlePriority as IdlePriority,
6+
unstable_LowPriority as LowPriority,
7+
unstable_runWithPriority as runWithPriority,
8+
} from 'scheduler';
9+
10+
export default function PriorityLevels() {
11+
const [defaultPriority, setDefaultPriority] = useState<boolean>(false);
12+
const [idlePriority, setIdlePriority] = useState<boolean>(false);
13+
const [normalPriority, setLowPriority] = useState<boolean>(false);
14+
15+
const resetSequence = useCallback(() => {
16+
setDefaultPriority(false);
17+
setLowPriority(false);
18+
setIdlePriority(false);
19+
}, []);
20+
21+
const startSequence = useCallback(() => {
22+
setDefaultPriority(true);
23+
runWithPriority(LowPriority, () => setLowPriority(true));
24+
runWithPriority(IdlePriority, () => setIdlePriority(true));
25+
}, []);
26+
27+
const labels = [];
28+
if (defaultPriority) {
29+
labels.push('(default priority)');
30+
}
31+
if (normalPriority) {
32+
labels.push('Low Priority');
33+
}
34+
if (idlePriority) {
35+
labels.push('Idle Priority');
36+
}
37+
38+
return (
39+
<Fragment>
40+
<h1>Priority Levels</h1>
41+
<button onClick={resetSequence}>Reset</button>
42+
<button onClick={startSequence}>Start sequence</button>
43+
<span>{labels.join(', ')}</span>
44+
</Fragment>
45+
);
46+
}

shells/dev/app/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
// This test harness mounts each test app as a separate root to test multi-root applications.
44

55
import { createElement } from 'react';
6-
import { render, unmountComponentAtNode } from 'react-dom';
6+
import {
7+
unmountComponentAtNode,
8+
// $FlowFixMe Flow does not yet know about createRoot()
9+
unstable_createRoot as createRoot,
10+
} from 'react-dom';
711
import DeeplyNestedComponents from './DeeplyNestedComponents';
812
import EditableProps from './EditableProps';
913
import ElementTypes from './ElementTypes';
1014
import InspectableElements from './InspectableElements';
1115
import InteractionTracing from './InteractionTracing';
16+
import PriorityLevels from './PriorityLevels';
1217
import ToDoList from './ToDoList';
1318
import Toggle from './Toggle';
1419
import SuspenseTree from './SuspenseTree';
@@ -24,7 +29,8 @@ function mountHelper(App) {
2429

2530
containers.push(container);
2631

27-
render(createElement(App), container);
32+
const root = createRoot(container);
33+
root.render(createElement(App));
2834
}
2935

3036
function mountTestApp() {
@@ -33,6 +39,7 @@ function mountTestApp() {
3339
mountHelper(InspectableElements);
3440
mountHelper(ElementTypes);
3541
mountHelper(EditableProps);
42+
mountHelper(PriorityLevels);
3643
mountHelper(Toggle);
3744
mountHelper(SuspenseTree);
3845
mountHelper(DeeplyNestedComponents);

src/__tests__/__snapshots__/inspectedElementContext-test.js.snap

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,28 @@ exports[`InspectedElementContext should inspect the currently selected element:
2727
}
2828
`;
2929
30+
exports[`InspectedElementContext should inspect the currently selected element: 2: Inspected element 2 2`] = `
31+
{
32+
"id": 2,
33+
"owners": null,
34+
"context": null,
35+
"hooks": [
36+
{
37+
"id": 0,
38+
"isStateEditable": true,
39+
"name": "State",
40+
"value": 1,
41+
"subHooks": []
42+
}
43+
],
44+
"props": {
45+
"foo": 1,
46+
"bar": "abc"
47+
},
48+
"state": null
49+
}
50+
`;
51+
3052
exports[`InspectedElementContext should poll for updates for the currently selected element: 1: mount 1`] = `
3153
[root]
3254
<Example>

src/__tests__/__snapshots__/profiling-test.js.snap

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Object {
1111
},
1212
"commitIndex": 0,
1313
"interactions": Array [],
14+
"priorityLevel": "Immediate",
1415
"rootID": 1,
1516
"selfDurations": Map {
1617
1 => 0,
@@ -33,6 +34,7 @@ Object {
3334
},
3435
"commitIndex": 1,
3536
"interactions": Array [],
37+
"priorityLevel": "Immediate",
3638
"rootID": 1,
3739
"selfDurations": Map {
3840
3 => 0,
@@ -53,6 +55,7 @@ Object {
5355
},
5456
"commitIndex": 2,
5557
"interactions": Array [],
58+
"priorityLevel": "Immediate",
5659
"rootID": 1,
5760
"selfDurations": Map {
5861
3 => 0,
@@ -70,6 +73,7 @@ Object {
7073
},
7174
"commitIndex": 3,
7275
"interactions": Array [],
76+
"priorityLevel": "Immediate",
7377
"rootID": 1,
7478
"selfDurations": Map {
7579
2 => 10,
@@ -91,6 +95,7 @@ Object {
9195
},
9296
"commitIndex": 0,
9397
"interactions": Array [],
98+
"priorityLevel": "Immediate",
9499
"rootID": 1,
95100
"selfDurations": Map {
96101
1 => 0,
@@ -110,6 +115,7 @@ Object {
110115
},
111116
"commitIndex": 1,
112117
"interactions": Array [],
118+
"priorityLevel": "Immediate",
113119
"rootID": 1,
114120
"selfDurations": Map {
115121
3 => 0,
@@ -127,6 +133,7 @@ Object {
127133
},
128134
"commitIndex": 2,
129135
"interactions": Array [],
136+
"priorityLevel": "Immediate",
130137
"rootID": 1,
131138
"selfDurations": Map {
132139
3 => 0,
@@ -141,6 +148,7 @@ Object {
141148
},
142149
"commitIndex": 3,
143150
"interactions": Array [],
151+
"priorityLevel": "Immediate",
144152
"rootID": 1,
145153
"selfDurations": Map {
146154
2 => 10,
@@ -324,6 +332,7 @@ Object {
324332
},
325333
"commitIndex": 0,
326334
"interactions": Array [],
335+
"priorityLevel": "Immediate",
327336
"rootID": 1,
328337
"selfDurations": Map {
329338
1 => 0,
@@ -344,6 +353,7 @@ Object {
344353
},
345354
"commitIndex": 0,
346355
"interactions": Array [],
356+
"priorityLevel": "Immediate",
347357
"rootID": 1,
348358
"selfDurations": Map {
349359
1 => 0,
@@ -362,6 +372,7 @@ Object {
362372
},
363373
"commitIndex": 1,
364374
"interactions": Array [],
375+
"priorityLevel": "Immediate",
365376
"rootID": 1,
366377
"selfDurations": Map {
367378
5 => 3,
@@ -447,6 +458,7 @@ Object {
447458
},
448459
"commitIndex": 0,
449460
"interactions": Array [],
461+
"priorityLevel": "Immediate",
450462
"rootID": 1,
451463
"selfDurations": Map {
452464
1 => 0,
@@ -464,6 +476,7 @@ Object {
464476
},
465477
"commitIndex": 1,
466478
"interactions": Array [],
479+
"priorityLevel": "Immediate",
467480
"rootID": 1,
468481
"selfDurations": Map {
469482
3 => 0,
@@ -482,6 +495,7 @@ Object {
482495
},
483496
"commitIndex": 2,
484497
"interactions": Array [],
498+
"priorityLevel": "Immediate",
485499
"rootID": 1,
486500
"selfDurations": Map {
487501
3 => 0,
@@ -696,6 +710,7 @@ Object {
696710
"timestamp": 0,
697711
},
698712
],
713+
"priorityLevel": "Immediate",
699714
"rootID": 1,
700715
"selfDurations": Map {
701716
1 => 0,
@@ -720,6 +735,7 @@ Object {
720735
"timestamp": 11,
721736
},
722737
],
738+
"priorityLevel": "Immediate",
723739
"rootID": 1,
724740
"selfDurations": Map {
725741
3 => 0,
@@ -906,6 +922,7 @@ Object {
906922
},
907923
"commitIndex": 0,
908924
"interactions": Array [],
925+
"priorityLevel": "Immediate",
909926
"rootID": 1,
910927
"selfDurations": Map {
911928
3 => 0,
@@ -923,6 +940,7 @@ Object {
923940
},
924941
"commitIndex": 1,
925942
"interactions": Array [],
943+
"priorityLevel": "Immediate",
926944
"rootID": 1,
927945
"selfDurations": Map {
928946
3 => 0,
@@ -937,6 +955,7 @@ Object {
937955
},
938956
"commitIndex": 2,
939957
"interactions": Array [],
958+
"priorityLevel": "Immediate",
940959
"rootID": 1,
941960
"selfDurations": Map {
942961
2 => 10,

0 commit comments

Comments
 (0)