Skip to content

Commit

Permalink
Add key to inspected-element error boundary (#21535)
Browse files Browse the repository at this point in the history
This way changing the selected element also recreates/resets the boundary automatically.
  • Loading branch information
Brian Vaughn authored May 19, 2021
1 parent 99995c1 commit ebcec3c
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
*/

import * as React from 'react';
import {useContext} from 'react';
import ErrorBoundary from '../ErrorBoundary';
import {TreeStateContext} from './TreeContext';
import styles from './InspectedElementErrorBoundary.css';

type WrapperProps = {|
Expand All @@ -18,9 +20,14 @@ type WrapperProps = {|
export default function InspectedElementErrorBoundaryWrapper({
children,
}: WrapperProps) {
// 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);
return (
<div className={styles.Wrapper}>
<ErrorBoundary canDismiss={true}>{children}</ErrorBoundary>
<ErrorBoundary key={selectedElementID} canDismiss={true}>
{children}
</ErrorBoundary>
</div>
);
}

0 comments on commit ebcec3c

Please sign in to comment.