Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,45 @@ type Props = {
defaultInspectedElementIndex?: ?number,
};

function getInitialState({
defaultOwnerID,
defaultInspectedElementID,
defaultInspectedElementIndex,
store,
}: {
defaultOwnerID?: ?number,
defaultInspectedElementID?: ?number,
defaultInspectedElementIndex?: ?number,
store: Store,
}): State {
return {
// Tree
numElements: store.numElements,
ownerSubtreeLeafElementID: null,

// Search
searchIndex: null,
searchResults: [],
searchText: '',

// Owners
ownerID: defaultOwnerID == null ? null : defaultOwnerID,
ownerFlatTree: null,

// Inspection element panel
inspectedElementID:
defaultInspectedElementID != null
? defaultInspectedElementID
: store.lastSelectedHostInstanceElementId,
inspectedElementIndex:
defaultInspectedElementIndex != null
? defaultInspectedElementIndex
: store.lastSelectedHostInstanceElementId
? store.getIndexOfElementID(store.lastSelectedHostInstanceElementId)
: null,
};
}

// TODO Remove TreeContextController wrapper element once global Context.write API exists.
function TreeContextController({
children,
Expand Down Expand Up @@ -866,32 +905,16 @@ function TreeContextController({
[store],
);

const [state, dispatch] = useReducer(reducer, {
// Tree
numElements: store.numElements,
ownerSubtreeLeafElementID: null,

// Search
searchIndex: null,
searchResults: [],
searchText: '',

// Owners
ownerID: defaultOwnerID == null ? null : defaultOwnerID,
ownerFlatTree: null,

// Inspection element panel
inspectedElementID:
defaultInspectedElementID != null
? defaultInspectedElementID
: store.lastSelectedHostInstanceElementId,
inspectedElementIndex:
defaultInspectedElementIndex != null
? defaultInspectedElementIndex
: store.lastSelectedHostInstanceElementId
? store.getIndexOfElementID(store.lastSelectedHostInstanceElementId)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where the warning originates from. We didn't use that index anymore since we no longer relied on the default state yet the warning continued to be issue. It should only be issued when we actually use a problematic value.

: null,
});
const [state, dispatch] = useReducer(
reducer,
{
defaultOwnerID,
defaultInspectedElementID,
defaultInspectedElementIndex,
store,
},
getInitialState,
);
const transitionDispatch = useMemo(
() => (action: Action) =>
startTransition(() => {
Expand Down
Loading