Skip to content

Commit 86503fe

Browse files
committed
Better devtool and stack handling
1 parent 859879c commit 86503fe

File tree

7 files changed

+366
-4
lines changed

7 files changed

+366
-4
lines changed

packages/react-devtools-shared/src/__tests__/storeComponentFilters-test.js

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,170 @@ describe('Store component filters', () => {
135135
});
136136

137137
// @reactVersion >= 16.0
138+
it('should filter Suspense', async () => {
139+
const Suspense = React.Suspense;
140+
await actAsync(async () =>
141+
render(
142+
<React.Fragment>
143+
<Suspense>
144+
<div>Visible</div>
145+
</Suspense>
146+
<Suspense>
147+
<div>Hidden</div>
148+
</Suspense>
149+
</React.Fragment>,
150+
),
151+
);
152+
153+
expect(store).toMatchInlineSnapshot(`
154+
[root]
155+
▾ <Suspense>
156+
<div>
157+
▾ <Suspense>
158+
<div>
159+
`);
160+
161+
await actAsync(
162+
async () =>
163+
(store.componentFilters = [
164+
utils.createElementTypeFilter(Types.ElementTypeActivity),
165+
]),
166+
);
167+
168+
expect(store).toMatchInlineSnapshot(`
169+
[root]
170+
▾ <Suspense>
171+
<div>
172+
▾ <Suspense>
173+
<div>
174+
`);
175+
176+
await actAsync(
177+
async () =>
178+
(store.componentFilters = [
179+
utils.createElementTypeFilter(Types.ElementTypeActivity, false),
180+
]),
181+
);
182+
183+
expect(store).toMatchInlineSnapshot(`
184+
[root]
185+
▾ <Suspense>
186+
<div>
187+
▾ <Suspense>
188+
<div>
189+
`);
190+
});
191+
192+
// TODO: How to gate by experimental?
193+
it.skip('should filter Activity', async () => {
194+
const Activity = React.unstable_Activity;
195+
196+
await actAsync(async () =>
197+
render(
198+
<React.Fragment>
199+
<Activity mode="visible">
200+
<div>Visible</div>
201+
</Activity>
202+
<Activity mode="hidden">
203+
<div>Hidden</div>
204+
</Activity>
205+
</React.Fragment>,
206+
),
207+
);
208+
209+
expect(store).toMatchInlineSnapshot(`
210+
[root]
211+
▾ <Activity>
212+
<div>
213+
▾ <Activity>
214+
<div>
215+
`);
216+
217+
await actAsync(
218+
async () =>
219+
(store.componentFilters = [
220+
utils.createElementTypeFilter(Types.ElementTypeActivity),
221+
]),
222+
);
223+
224+
expect(store).toMatchInlineSnapshot(`
225+
[root]
226+
<div>
227+
<div>
228+
`);
229+
230+
await actAsync(
231+
async () =>
232+
(store.componentFilters = [
233+
utils.createElementTypeFilter(Types.ElementTypeActivity, false),
234+
]),
235+
);
236+
237+
expect(store).toMatchInlineSnapshot(`
238+
[root]
239+
▾ <Activity>
240+
<div>
241+
▾ <Activity>
242+
<div>
243+
`);
244+
});
245+
246+
// TODO: How to gate by experimental?
247+
it.skip('should filter ViewTransition', async () => {
248+
const ViewTransition = React.unstable_ViewTransition;
249+
250+
await actAsync(async () =>
251+
render(
252+
<React.Fragment>
253+
<ViewTransition>
254+
<div>Visible</div>
255+
</ViewTransition>
256+
<ViewTransition>
257+
<div>Hidden</div>
258+
</ViewTransition>
259+
</React.Fragment>,
260+
),
261+
);
262+
263+
expect(store).toMatchInlineSnapshot(`
264+
[root]
265+
▾ <ViewTransition>
266+
<div>
267+
▾ <ViewTransition>
268+
<div>
269+
`);
270+
271+
await actAsync(
272+
async () =>
273+
(store.componentFilters = [
274+
utils.createElementTypeFilter(Types.ElementTypeActivity),
275+
]),
276+
);
277+
278+
expect(store).toMatchInlineSnapshot(`
279+
[root]
280+
▾ <ViewTransition>
281+
<div>
282+
▾ <ViewTransition>
283+
<div>
284+
`);
285+
286+
await actAsync(
287+
async () =>
288+
(store.componentFilters = [
289+
utils.createElementTypeFilter(Types.ElementTypeActivity, false),
290+
]),
291+
);
292+
293+
expect(store).toMatchInlineSnapshot(`
294+
[root]
295+
▾ <ViewTransition>
296+
<div>
297+
▾ <ViewTransition>
298+
<div>
299+
`);
300+
});
301+
138302
it('should ignore invalid ElementTypeRoot filter', async () => {
139303
const Component = () => <div>Hi</div>;
140304

packages/react-devtools-shared/src/backend/fiber/DevToolsFiberComponentStack.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export function describeFiber(
4444
ForwardRef,
4545
ClassComponent,
4646
ViewTransitionComponent,
47+
ActivityComponent,
4748
} = workTagMap;
4849

4950
switch (workInProgress.tag) {
@@ -60,6 +61,8 @@ export function describeFiber(
6061
return describeBuiltInComponentFrame('SuspenseList');
6162
case ViewTransitionComponent:
6263
return describeBuiltInComponentFrame('ViewTransition');
64+
case ActivityComponent:
65+
return describeBuiltInComponentFrame('Activity');
6366
case FunctionComponent:
6467
case IndeterminateComponent:
6568
case SimpleMemoComponent:
@@ -154,6 +157,7 @@ export function getOwnerStackByFiberInDev(
154157
SuspenseComponent,
155158
SuspenseListComponent,
156159
ViewTransitionComponent,
160+
ActivityComponent,
157161
} = workTagMap;
158162
try {
159163
let info = '';
@@ -184,6 +188,9 @@ export function getOwnerStackByFiberInDev(
184188
case ViewTransitionComponent:
185189
info += describeBuiltInComponentFrame('ViewTransition');
186190
break;
191+
case ActivityComponent:
192+
info += describeBuiltInComponentFrame('Activity');
193+
break;
187194
}
188195

189196
let owner: void | null | Fiber | ReactComponentInfo = workInProgress;

packages/react-devtools-shared/src/backend/fiber/renderer.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
ElementTypeSuspenseList,
2929
ElementTypeTracingMarker,
3030
ElementTypeViewTransition,
31+
ElementTypeActivity,
3132
ElementTypeVirtual,
3233
StrictMode,
3334
} from 'react-devtools-shared/src/frontend/types';
@@ -146,7 +147,6 @@ import type {
146147
import type {Source} from 'react-devtools-shared/src/shared/types';
147148
import {getSourceLocationByFiber} from './DevToolsFiberComponentStack';
148149
import {formatOwnerStack} from '../shared/DevToolsOwnerStack';
149-
import {ActivityComponent} from 'react-reconciler/src/ReactWorkTags';
150150

151151
// Kinds
152152
const FIBER_INSTANCE = 0;
@@ -578,6 +578,7 @@ export function getInternalReactConstants(version: string): {
578578
TracingMarkerComponent,
579579
Throw,
580580
ViewTransitionComponent,
581+
ActivityComponent,
581582
} = ReactTypeOfWork;
582583

583584
function resolveFiberType(type: any): $FlowFixMe {
@@ -900,6 +901,7 @@ export function attach(
900901
StrictModeBits,
901902
} = getInternalReactConstants(version);
902903
const {
904+
ActivityComponent,
903905
CacheComponent,
904906
ClassComponent,
905907
ContextConsumer,
@@ -1488,7 +1490,6 @@ export function attach(
14881490
return true;
14891491
case HostPortal:
14901492
case HostText:
1491-
case ActivityComponent:
14921493
case LegacyHiddenComponent:
14931494
case OffscreenComponent:
14941495
case Throw:
@@ -1574,6 +1575,8 @@ export function attach(
15741575
const {type, tag} = fiber;
15751576

15761577
switch (tag) {
1578+
case ActivityComponent:
1579+
return ElementTypeActivity;
15771580
case ClassComponent:
15781581
case IncompleteClassComponent:
15791582
return ElementTypeClass;

packages/react-devtools-shared/src/devtools/views/Settings/ComponentsSettings.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ export default function ComponentsSettings({
472472
((parseInt(currentTarget.value, 10): any): ElementType),
473473
)
474474
}>
475+
{/* TODO: currently only experimental, only list this if it's available */}
476+
{/*<option value={ElementTypeActivity}>activity</option>*/}
475477
<option value={ElementTypeClass}>class</option>
476478
<option value={ElementTypeContext}>context</option>
477479
<option value={ElementTypeFunction}>function</option>
@@ -485,6 +487,10 @@ export default function ComponentsSettings({
485487
<option value={ElementTypeOtherOrUnknown}>other</option>
486488
<option value={ElementTypeProfiler}>profiler</option>
487489
<option value={ElementTypeSuspense}>suspense</option>
490+
{/* TODO: currently only experimental, only list this if it's available */}
491+
{/*<option value={ElementTypeViewTransition}>*/}
492+
{/* view transition*/}
493+
{/*</option>*/}
488494
</select>
489495
)}
490496
{(componentFilter.type === ComponentFilterLocation ||

packages/react-devtools-shared/src/frontend/types.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export const ElementTypeSuspenseList = 13;
5050
export const ElementTypeTracingMarker = 14;
5151
export const ElementTypeVirtual = 15;
5252
export const ElementTypeViewTransition = 16;
53+
export const ElementTypeActivity = 17;
5354

5455
// Different types of elements displayed in the Elements tree.
5556
// These types may be used to visually distinguish types,
@@ -68,7 +69,8 @@ export type ElementType =
6869
| 13
6970
| 14
7071
| 15
71-
| 16;
72+
| 16
73+
| 17;
7274

7375
// WARNING
7476
// The values below are referenced by ComponentFilters (which are saved via localStorage).

packages/react-reconciler/src/ReactFiberComponentStack.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
ClassComponent,
2525
HostText,
2626
ViewTransitionComponent,
27+
ActivityComponent,
2728
} from './ReactWorkTags';
2829
import {
2930
describeBuiltInComponentFrame,
@@ -53,6 +54,8 @@ function describeFiber(fiber: Fiber): string {
5354
return describeFunctionComponentFrame(fiber.type.render);
5455
case ClassComponent:
5556
return describeClassComponentFrame(fiber.type);
57+
case ActivityComponent:
58+
return describeBuiltInComponentFrame('Activity');
5659
case ViewTransitionComponent:
5760
if (enableViewTransition) {
5861
return describeBuiltInComponentFrame('ViewTransition');
@@ -129,9 +132,12 @@ export function getOwnerStackByFiberInDev(workInProgress: Fiber): string {
129132
case SuspenseListComponent:
130133
info += describeBuiltInComponentFrame('SuspenseList');
131134
break;
135+
case ActivityComponent:
136+
info += describeBuiltInComponentFrame('Activity');
137+
break;
132138
case ViewTransitionComponent:
133139
if (enableViewTransition) {
134-
info += describeBuiltInComponentFrame('SuspenseList');
140+
info += describeBuiltInComponentFrame('ViewTransition');
135141
break;
136142
}
137143
// Fallthrough

0 commit comments

Comments
 (0)