mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Reset inspected element cache in the event of an error (#21821)
This commit is contained in:
+1
-1
@@ -108,8 +108,8 @@ export function InspectedElementContextController({children}: Props) {
|
||||
}
|
||||
|
||||
// Don't load a stale element from the backend; it wastes bridge bandwidth.
|
||||
let inspectedElement = null;
|
||||
let hookNames: HookNames | null = null;
|
||||
let inspectedElement = null;
|
||||
if (!elementHasChanged && element !== null) {
|
||||
inspectedElement = inspectElement(element, state.path, store, bridge);
|
||||
|
||||
|
||||
Vendored
+16
-2
@@ -8,9 +8,14 @@
|
||||
*/
|
||||
|
||||
import * as React from 'react';
|
||||
import {useContext} from 'react';
|
||||
import {
|
||||
useCallback,
|
||||
useContext,
|
||||
unstable_useCacheRefresh as useCacheRefresh,
|
||||
} from 'react';
|
||||
import ErrorBoundary from '../ErrorBoundary';
|
||||
import {TreeStateContext} from './TreeContext';
|
||||
import {clearCacheBecauseOfError} from '../../../inspectedElementCache';
|
||||
import styles from './InspectedElementErrorBoundary.css';
|
||||
|
||||
type WrapperProps = {|
|
||||
@@ -23,9 +28,18 @@ export default function InspectedElementErrorBoundaryWrapper({
|
||||
// Key on the selected element ID so that changing the selected element automatically hides the boundary.
|
||||
// This seems best since an error inspecting one element isn't likely to be relevant to another element.
|
||||
const {selectedElementID} = useContext(TreeStateContext);
|
||||
|
||||
const refresh = useCacheRefresh();
|
||||
const handleDsmiss = useCallback(() => {
|
||||
clearCacheBecauseOfError(refresh);
|
||||
}, [refresh]);
|
||||
|
||||
return (
|
||||
<div className={styles.Wrapper}>
|
||||
<ErrorBoundary key={selectedElementID} canDismiss={true}>
|
||||
<ErrorBoundary
|
||||
key={selectedElementID}
|
||||
canDismiss={true}
|
||||
onBeforeDismissCallback={handleDsmiss}>
|
||||
{children}
|
||||
</ErrorBoundary>
|
||||
</div>
|
||||
|
||||
+6
@@ -17,6 +17,7 @@ import SuspendingErrorView from './SuspendingErrorView';
|
||||
type Props = {|
|
||||
children: React$Node,
|
||||
canDismiss?: boolean,
|
||||
onBeforeDismissCallback?: () => void,
|
||||
store?: Store,
|
||||
|};
|
||||
|
||||
@@ -118,6 +119,11 @@ export default class ErrorBoundary extends Component<Props, State> {
|
||||
}
|
||||
|
||||
_dismissError = () => {
|
||||
const onBeforeDismissCallback = this.props.onBeforeDismissCallback;
|
||||
if (typeof onBeforeDismissCallback === 'function') {
|
||||
onBeforeDismissCallback();
|
||||
}
|
||||
|
||||
this.setState(InitialState);
|
||||
};
|
||||
|
||||
|
||||
@@ -190,3 +190,10 @@ export function checkForUpdate({
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function clearCacheBecauseOfError(refresh: RefreshFunction): void {
|
||||
startTransition(() => {
|
||||
const map = createMap();
|
||||
refresh(createMap, map);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user