Skip to content

Commit

Permalink
Remove Suspense around InspectedElement
Browse files Browse the repository at this point in the history
We should be just using the Transition value "inspectedElementID".

We could useDeferredValue but we already have an implementation of this
ID using a reducer but it would be more idiomatic to useDeferredValue.
  • Loading branch information
sebmarkbage committed Aug 1, 2024
1 parent edfaa99 commit 8ee7311
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,11 @@ describe('InspectedElement', () => {
<SettingsContextController>
<TreeContextController
defaultSelectedElementID={defaultSelectedElementID}
defaultSelectedElementIndex={defaultSelectedElementIndex}>
<React.Suspense fallback="Loading...">
<InspectedElementContextController>
{children}
</InspectedElementContextController>
</React.Suspense>
defaultSelectedElementIndex={defaultSelectedElementIndex}
defaultInspectedElementID={defaultSelectedElementID}>
<InspectedElementContextController>
{children}
</InspectedElementContextController>
</TreeContextController>
</SettingsContextController>
</StoreContext.Provider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@
*/

import * as React from 'react';
import {
Fragment,
Suspense,
useEffect,
useLayoutEffect,
useReducer,
useRef,
} from 'react';
import {Fragment, useEffect, useLayoutEffect, useReducer, useRef} from 'react';
import Tree from './Tree';
import {OwnersListContextController} from './OwnersListContext';
import portaledContent from '../portaledContent';
Expand Down Expand Up @@ -169,11 +162,9 @@ function Components(_: {}) {
<div className={styles.InspectedElementWrapper}>
<NativeStyleContextController>
<InspectedElementErrorBoundary>
<Suspense fallback={<Loading />}>
<InspectedElementContextController>
<InspectedElement />
</InspectedElementContextController>
</Suspense>
<InspectedElementContextController>
<InspectedElement />
</InspectedElementContextController>
</InspectedElementErrorBoundary>
</NativeStyleContextController>
</div>
Expand All @@ -186,10 +177,6 @@ function Components(_: {}) {
);
}

function Loading() {
return <div className={styles.Loading}>Loading...</div>;
}

const LOCAL_STORAGE_KEY = 'React::DevTools::createResizeReducer';
const VERTICAL_MODE_MAX_WIDTH = 600;
const MINIMUM_SIZE = 50;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export type Props = {
export function InspectedElementContextController({
children,
}: Props): React.Node {
const {selectedElementID} = useContext(TreeStateContext);
const {inspectedElementID} = useContext(TreeStateContext);
const fetchFileWithCaching = useContext(FetchFileWithCachingContext);
const bridge = useContext(BridgeContext);
const store = useContext(StoreContext);
Expand All @@ -93,7 +93,9 @@ export function InspectedElementContextController({
});

const element =
selectedElementID !== null ? store.getElementByID(selectedElementID) : null;
inspectedElementID !== null
? store.getElementByID(inspectedElementID)
: null;

const alreadyLoadedHookNames =
element != null && hasAlreadyLoadedHookNames(element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function InspectedElementErrorBoundaryWrapper({
}: WrapperProps): React.Node {
// 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 {inspectedElementID} = useContext(TreeStateContext);

const refresh = useCacheRefresh();
const handleDsmiss = useCallback(() => {
Expand All @@ -37,7 +37,7 @@ export default function InspectedElementErrorBoundaryWrapper({
return (
<div className={styles.Wrapper}>
<ErrorBoundary
key={selectedElementID}
key={inspectedElementID}
canDismiss={true}
onBeforeDismissCallback={handleDsmiss}>
{children}
Expand Down

0 comments on commit 8ee7311

Please sign in to comment.