fix[devtools/inspectElement]: dont pause initial inspectElement call when user switches tabs (#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 https://github.com/facebook/react/pull/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
This commit is contained in:
Ruslan Lesiutin
2023-10-10 18:10:17 +01:00
committed by GitHub
parent 151e75a128
commit 77ec61885f
58 changed files with 305 additions and 282 deletions
+1 -1
View File
@@ -7,7 +7,7 @@
* @flow
*/
import type {StyleXPlugin} from 'react-devtools-shared/src/types';
import type {StyleXPlugin} from 'react-devtools-shared/src/frontend/types';
import isArray from 'react-devtools-shared/src/isArray';
const cachedStyleNameToValueMap: Map<string, string> = new Map();
+1 -1
View File
@@ -42,7 +42,7 @@ import type {
import type {
ComponentFilter,
BrowserTheme,
} from 'react-devtools-shared/src/types';
} from 'react-devtools-shared/src/frontend/types';
import {isSynchronousXHRSupported} from './utils';
const debug = (methodName: string, ...args: Array<string>) => {
@@ -13,7 +13,7 @@ import {
ElementTypeRoot,
ElementTypeHostComponent,
ElementTypeOtherOrUnknown,
} from 'react-devtools-shared/src/types';
} from 'react-devtools-shared/src/frontend/types';
import {getUID, utfEncodeString, printOperationsArray} from '../../utils';
import {
cleanForBridge,
@@ -50,7 +50,7 @@ import type {
import type {
ComponentFilter,
ElementType,
} from 'react-devtools-shared/src/types';
} from 'react-devtools-shared/src/frontend/types';
import type {InspectedElement, SerializedElement} from '../types';
export type InternalInstance = Object;
+2 -2
View File
@@ -25,7 +25,7 @@ import {
ElementTypeSuspenseList,
ElementTypeTracingMarker,
StrictMode,
} from 'react-devtools-shared/src/types';
} from 'react-devtools-shared/src/frontend/types';
import {
deletePathInObject,
getDisplayName,
@@ -121,7 +121,7 @@ import type {
ComponentFilter,
ElementType,
Plugins,
} from 'react-devtools-shared/src/types';
} from 'react-devtools-shared/src/frontend/types';
type getDisplayNameForFiberType = (fiber: Fiber) => string | null;
type getTypeSymbolType = (type: any) => symbol | number;
+2 -2
View File
@@ -21,14 +21,14 @@ import type {
ComponentFilter,
ElementType,
Plugins,
} from 'react-devtools-shared/src/types';
} from 'react-devtools-shared/src/frontend/types';
import type {
ResolveNativeStyle,
SetupNativeStyleEditor,
} from 'react-devtools-shared/src/backend/NativeStyleEditor/setupNativeStyleEditor';
import type {InitBackend} from 'react-devtools-shared/src/backend';
import type {TimelineDataExport} from 'react-devtools-timeline/src/types';
import type {BrowserTheme} from 'react-devtools-shared/src/types';
import type {BrowserTheme} from 'react-devtools-shared/src/frontend/types';
import type {BackendBridge} from 'react-devtools-shared/src/bridge';
import type Agent from './agent';
+1 -1
View File
@@ -12,7 +12,7 @@ import {compareVersions} from 'compare-versions';
import {dehydrate} from '../hydration';
import isArray from 'shared/isArray';
import type {DehydratedData} from 'react-devtools-shared/src/devtools/views/Components/types';
import type {DehydratedData} from 'react-devtools-shared/src/frontend/types';
// TODO: update this to the first React version that has a corresponding DevTools backend
const FIRST_DEVTOOLS_BACKEND_LOCKSTEP_VER = '999.9.9';