Skip to content

Commit 83ee7f9

Browse files
committed
Don't persist Activity slice filters
1 parent 4ad0629 commit 83ee7f9

File tree

5 files changed

+39
-28
lines changed

5 files changed

+39
-28
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3283,8 +3283,6 @@ describe('Store', () => {
32833283
<Suspense name="Outer" rects={null}>
32843284
`);
32853285

3286-
console.log('...........................');
3287-
32883286
await actAsync(() => {
32893287
resolve('loaded');
32903288
});

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import {
5454
renamePathInObject,
5555
setInObject,
5656
utfEncodeString,
57-
filterOutLocationComponentFilters,
57+
persistableComponentFilters,
5858
} from 'react-devtools-shared/src/utils';
5959
import {
6060
formatConsoleArgumentsToSingleString,
@@ -1481,14 +1481,21 @@ export function attach(
14811481
hideElementsWithEnvs.add(componentFilter.value);
14821482
break;
14831483
case ComponentFilterActivitySlice:
1484-
activitySlice = nextActivitySlice;
1485-
if (activitySlice === null) {
1484+
if (
1485+
nextActivitySlice !== null &&
1486+
nextActivitySlice.tag === ActivityComponent
1487+
) {
1488+
activitySlice = nextActivitySlice;
1489+
isInActivitySlice = false;
1490+
} else {
14861491
// We're not filtering by activity slice after all. Consider everything
14871492
// to be in the slice.
14881493
isInActivitySlice = true;
1489-
} else {
1490-
isInActivitySlice = false;
1494+
activitySlice = null;
1495+
// TODO: This is not sent to the frontend.
1496+
componentFilter.isEnabled = false;
14911497
}
1498+
14921499
break;
14931500
default:
14941501
console.warn(
@@ -1503,11 +1510,9 @@ export function attach(
15031510
// because they are stored in localStorage within the context of the extension.
15041511
// Instead it relies on the extension to pass filters through.
15051512
if (window.__REACT_DEVTOOLS_COMPONENT_FILTERS__ != null) {
1506-
const componentFiltersWithoutLocationBasedOnes =
1507-
filterOutLocationComponentFilters(
1508-
window.__REACT_DEVTOOLS_COMPONENT_FILTERS__,
1509-
);
1510-
applyComponentFilters(componentFiltersWithoutLocationBasedOnes);
1513+
const restoredComponentFilters: Array<ComponentFilter> =
1514+
persistableComponentFilters(window.__REACT_DEVTOOLS_COMPONENT_FILTERS__);
1515+
applyComponentFilters(restoredComponentFilters);
15111516
} else {
15121517
// Unfortunately this feature is not expected to work for React Native for now.
15131518
// It would be annoying for us to spam YellowBox warnings with unactionable stuff,

packages/react-devtools-shared/src/devtools/store.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
SUSPENSE_TREE_OPERATION_RESIZE,
2828
SUSPENSE_TREE_OPERATION_SUSPENDERS,
2929
} from '../constants';
30-
import {ElementTypeActivity, ElementTypeRoot} from '../frontend/types';
30+
import {ElementTypeRoot} from '../frontend/types';
3131
import {
3232
getSavedComponentFilters,
3333
setSavedComponentFilters,

packages/react-devtools-shared/src/devtools/views/SuspenseTab/ActivityList.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,26 @@
66
*
77
* @flow
88
*/
9-
import type {Element} from 'react-devtools-shared/src/frontend/types';
9+
import type {
10+
Element,
11+
ActivitySliceFilter,
12+
ComponentFilter,
13+
} from 'react-devtools-shared/src/frontend/types';
1014
import typeof {
1115
SyntheticMouseEvent,
1216
SyntheticKeyboardEvent,
1317
} from 'react-dom-bindings/src/events/SyntheticEvent';
1418

1519
import * as React from 'react';
1620
import {useContext, useTransition} from 'react';
21+
import {ComponentFilterActivitySlice} from 'react-devtools-shared/src/frontend/types';
1722
import styles from './ActivityList.css';
1823
import {
1924
TreeStateContext,
2025
TreeDispatcherContext,
2126
} from '../Components/TreeContext';
2227
import {useHighlightHostInstance} from '../hooks';
2328
import {StoreContext} from '../context';
24-
import type {
25-
ActivitySliceFilter,
26-
ComponentFilter,
27-
} from '../../../frontend/types';
2829

2930
export function useChangeActivitySliceAction(): [
3031
boolean,
@@ -40,7 +41,7 @@ export function useChangeActivitySliceAction(): [
4041
// Remove any existing activity slice filter
4142
for (let i = 0; i < store.componentFilters.length; i++) {
4243
const filter = store.componentFilters[i];
43-
if (filter.type !== 6) {
44+
if (filter.type !== ComponentFilterActivitySlice) {
4445
nextFilters.push(filter);
4546
}
4647
}

packages/react-devtools-shared/src/utils.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
SUSPENSE_TREE_OPERATION_SUSPENDERS,
4848
} from './constants';
4949
import {
50+
ComponentFilterActivitySlice,
5051
ComponentFilterElementType,
5152
ComponentFilterLocation,
5253
ElementTypeHostComponent,
@@ -467,7 +468,7 @@ export function getSavedComponentFilters(): Array<ComponentFilter> {
467468
);
468469
if (raw != null) {
469470
const parsedFilters: Array<ComponentFilter> = JSON.parse(raw);
470-
return filterOutLocationComponentFilters(parsedFilters);
471+
return persistableComponentFilters(parsedFilters);
471472
}
472473
} catch (error) {}
473474
return getDefaultComponentFilters();
@@ -478,16 +479,11 @@ export function setSavedComponentFilters(
478479
): void {
479480
localStorageSetItem(
480481
LOCAL_STORAGE_COMPONENT_FILTER_PREFERENCES_KEY,
481-
JSON.stringify(filterOutLocationComponentFilters(componentFilters)),
482+
JSON.stringify(persistableComponentFilters(componentFilters)),
482483
);
483484
}
484485

485-
// Following __debugSource removal from Fiber, the new approach for finding the source location
486-
// of a component, represented by the Fiber, is based on lazily generating and parsing component stack frames
487-
// To find the original location, React DevTools will perform symbolication, source maps are required for that.
488-
// In order to start filtering Fibers, we need to find location for all of them, which can't be done lazily.
489-
// Eager symbolication can become quite expensive for large applications.
490-
export function filterOutLocationComponentFilters(
486+
export function persistableComponentFilters(
491487
componentFilters: Array<ComponentFilter>,
492488
): Array<ComponentFilter> {
493489
// This is just an additional check to preserve the previous state
@@ -496,7 +492,18 @@ export function filterOutLocationComponentFilters(
496492
return componentFilters;
497493
}
498494

499-
return componentFilters.filter(f => f.type !== ComponentFilterLocation);
495+
return componentFilters.filter(f => {
496+
return (
497+
// Following __debugSource removal from Fiber, the new approach for finding the source location
498+
// of a component, represented by the Fiber, is based on lazily generating and parsing component stack frames
499+
// To find the original location, React DevTools will perform symbolication, source maps are required for that.
500+
// In order to start filtering Fibers, we need to find location for all of them, which can't be done lazily.
501+
// Eager symbolication can become quite expensive for large applications.
502+
f.type !== ComponentFilterLocation &&
503+
// Activity slice filters are based on DevTools instance IDs which do not persist across sessions.
504+
f.type !== ComponentFilterActivitySlice
505+
);
506+
});
500507
}
501508

502509
const vscodeFilepath = 'vscode://file/{path}:{line}:{column}';

0 commit comments

Comments
 (0)