Skip to content

Commit 77ec618

Browse files
authored
fix[devtools/inspectElement]: dont pause initial inspectElement call when user switches tabs (facebook#27488)
There are not so many changes, most of them are changing imports, because I've moved types for UI in a single file. In facebook#27357 I've added support for pausing polling events: when user inspects an element, we start polling React DevTools backend for updates in props / state. If user switches tabs, extension's service worker can be killed by browser and this polling will start spamming errors. What I've missed is that we also have a separate call for this API, but which is executed only once when user selects an element. We don't handle promise rejection here and this can lead to some errors when user selects an element and switches tabs right after it. The only change here is that this API now has `shouldListenToPauseEvents` param, which is `true` for polling, so we will pause polling once user switches tabs. It is `false` by default, so we won't pause initial call by accident. https://github.com/hoxyq/react/blob/af8beeebf63b5824497fcd0bb35b7c0ac8fe60a0/packages/react-devtools-shared/src/backendAPI.js#L96
1 parent 151e75a commit 77ec618

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+305
-282
lines changed

packages/react-devtools-core/src/backend.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
} from './cachedSettings';
2323

2424
import type {BackendBridge} from 'react-devtools-shared/src/bridge';
25-
import type {ComponentFilter} from 'react-devtools-shared/src/types';
25+
import type {ComponentFilter} from 'react-devtools-shared/src/frontend/types';
2626
import type {DevToolsHook} from 'react-devtools-shared/src/backend/types';
2727
import type {ResolveNativeStyle} from 'react-devtools-shared/src/backend/NativeStyleEditor/setupNativeStyleEditor';
2828

packages/react-devtools-core/src/standalone.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
import {localStorageSetItem} from 'react-devtools-shared/src/storage';
3434

3535
import type {FrontendBridge} from 'react-devtools-shared/src/bridge';
36-
import type {InspectedElement} from 'react-devtools-shared/src/devtools/views/Components/types';
36+
import type {InspectedElement} from 'react-devtools-shared/src/frontend/types';
3737

3838
installHook(window);
3939

packages/react-devtools-inline/src/backend.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {installHook} from 'react-devtools-shared/src/hook';
88
import setupNativeStyleEditor from 'react-devtools-shared/src/backend/NativeStyleEditor/setupNativeStyleEditor';
99

1010
import type {BackendBridge} from 'react-devtools-shared/src/bridge';
11-
import type {Wall} from 'react-devtools-shared/src/types';
11+
import type {Wall} from 'react-devtools-shared/src/frontend/types';
1212

1313
function startActivation(contentWindow: any, bridge: BackendBridge) {
1414
const onSavedPreferences = (data: $FlowFixMe) => {

packages/react-devtools-inline/src/frontend.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
getHideConsoleLogsInStrictMode,
1414
} from 'react-devtools-shared/src/utils';
1515

16-
import type {Wall} from 'react-devtools-shared/src/types';
16+
import type {Wall} from 'react-devtools-shared/src/frontend/types';
1717
import type {FrontendBridge} from 'react-devtools-shared/src/bridge';
1818
import type {Props} from 'react-devtools-shared/src/devtools/views/DevTools';
1919

packages/react-devtools-shared/src/__tests__/legacy/inspectElement-test.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@ describe('InspectedElementContext', () => {
3030
): Promise<Object> {
3131
const rendererID = ((store.getRendererIDForElement(id): any): number);
3232
const promise = backendAPI
33-
.inspectElement({
34-
bridge,
35-
id,
36-
path,
37-
rendererID,
38-
})
33+
.inspectElement(bridge, false, id, path, rendererID)
3934
.then(data =>
4035
backendAPI.convertInspectedElementBackendToFrontend(data.value),
4136
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import typeof ReactTestRenderer from 'react-test-renderer';
11-
import type {Element} from 'react-devtools-shared/src/devtools/views/Components/types';
11+
import type {Element} from 'react-devtools-shared/src/frontend/types';
1212
import type {FrontendBridge} from 'react-devtools-shared/src/bridge';
1313
import type Store from 'react-devtools-shared/src/devtools/store';
1414

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ describe('ProfilerStore', () => {
187187
utils.act(() => {
188188
const {
189189
ElementTypeHostComponent,
190-
} = require('react-devtools-shared/src/types');
190+
} = require('react-devtools-shared/src/frontend/types');
191191
store.componentFilters = [
192192
utils.createElementTypeFilter(ElementTypeHostComponent),
193193
];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('Store component filters', () => {
3636
store.recordChangeDescriptions = true;
3737

3838
React = require('react');
39-
Types = require('react-devtools-shared/src/types');
39+
Types = require('react-devtools-shared/src/frontend/types');
4040
utils = require('./utils');
4141

4242
legacyRender = utils.legacyRender;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import typeof ReactTestRenderer from 'react-test-renderer';
1212
import type {FrontendBridge} from 'react-devtools-shared/src/bridge';
1313
import type Store from 'react-devtools-shared/src/devtools/store';
1414
import type {ProfilingDataFrontend} from 'react-devtools-shared/src/devtools/views/Profiler/types';
15-
import type {ElementType} from 'react-devtools-shared/src/types';
15+
import type {ElementType} from 'react-devtools-shared/src/frontend/types';
1616

1717
export function act(
1818
callback: Function,
@@ -86,7 +86,7 @@ export function createDisplayNameFilter(
8686
source: string,
8787
isEnabled: boolean = true,
8888
) {
89-
const Types = require('react-devtools-shared/src/types');
89+
const Types = require('react-devtools-shared/src/frontend/types');
9090
let isValid = true;
9191
try {
9292
new RegExp(source); // eslint-disable-line no-new
@@ -102,7 +102,7 @@ export function createDisplayNameFilter(
102102
}
103103

104104
export function createHOCFilter(isEnabled: boolean = true) {
105-
const Types = require('react-devtools-shared/src/types');
105+
const Types = require('react-devtools-shared/src/frontend/types');
106106
return {
107107
type: Types.ComponentFilterHOC,
108108
isEnabled,
@@ -114,7 +114,7 @@ export function createElementTypeFilter(
114114
elementType: ElementType,
115115
isEnabled: boolean = true,
116116
) {
117-
const Types = require('react-devtools-shared/src/types');
117+
const Types = require('react-devtools-shared/src/frontend/types');
118118
return {
119119
type: Types.ComponentFilterElementType,
120120
isEnabled,
@@ -126,7 +126,7 @@ export function createLocationFilter(
126126
source: string,
127127
isEnabled: boolean = true,
128128
) {
129-
const Types = require('react-devtools-shared/src/types');
129+
const Types = require('react-devtools-shared/src/frontend/types');
130130
let isValid = true;
131131
try {
132132
new RegExp(source); // eslint-disable-line no-new

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {StyleXPlugin} from 'react-devtools-shared/src/types';
10+
import type {StyleXPlugin} from 'react-devtools-shared/src/frontend/types';
1111
import isArray from 'react-devtools-shared/src/isArray';
1212

1313
const cachedStyleNameToValueMap: Map<string, string> = new Map();

0 commit comments

Comments
 (0)