-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try disabling async mode provider around selected block in ListView #34519
Changes from all commits
a0c3238
7850761
398c3c5
086c14b
83ab2ae
d17c44f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
import { useMergeRefs } from '@wordpress/compose'; | ||
import { __experimentalTreeGrid as TreeGrid } from '@wordpress/components'; | ||
import { useDispatch } from '@wordpress/data'; | ||
import { AsyncModeProvider, useDispatch } from '@wordpress/data'; | ||
import { | ||
useCallback, | ||
useEffect, | ||
|
@@ -62,7 +62,11 @@ function ListView( | |
}, | ||
ref | ||
) { | ||
const { clientIdsTree, selectedClientIds } = useListViewClientIds( | ||
const { | ||
clientIdsTree, | ||
selectedClientIds, | ||
draggedClientIds, | ||
} = useListViewClientIds( | ||
blocks, | ||
showOnlyCurrentHierarchy, | ||
__experimentalPersistentListViewFeatures | ||
|
@@ -86,18 +90,24 @@ function ListView( | |
isMounted.current = true; | ||
}, [] ); | ||
|
||
const expand = ( clientId ) => { | ||
if ( ! clientId ) { | ||
return; | ||
} | ||
setExpandedState( { type: 'expand', clientId } ); | ||
}; | ||
const collapse = ( clientId ) => { | ||
if ( ! clientId ) { | ||
return; | ||
} | ||
setExpandedState( { type: 'collapse', clientId } ); | ||
}; | ||
const expand = useCallback( | ||
( clientId ) => { | ||
if ( ! clientId ) { | ||
return; | ||
} | ||
setExpandedState( { type: 'expand', clientId } ); | ||
}, | ||
[ setExpandedState ] | ||
); | ||
const collapse = useCallback( | ||
( clientId ) => { | ||
if ( ! clientId ) { | ||
return; | ||
} | ||
setExpandedState( { type: 'collapse', clientId } ); | ||
}, | ||
[ setExpandedState ] | ||
); | ||
Comment on lines
+93
to
+110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are used in a context provider, so I think they should be memoized to stop the consumers from constantly updating. |
||
const expandRow = ( row ) => { | ||
expand( row?.dataset?.block ); | ||
}; | ||
|
@@ -110,6 +120,8 @@ function ListView( | |
__experimentalFeatures, | ||
__experimentalPersistentListViewFeatures, | ||
isTreeGridMounted: isMounted.current, | ||
draggedClientIds, | ||
selectedClientIds, | ||
expandedState, | ||
expand, | ||
collapse, | ||
|
@@ -118,14 +130,16 @@ function ListView( | |
__experimentalFeatures, | ||
__experimentalPersistentListViewFeatures, | ||
isMounted.current, | ||
draggedClientIds, | ||
selectedClientIds, | ||
expandedState, | ||
expand, | ||
collapse, | ||
] | ||
); | ||
|
||
return ( | ||
<> | ||
<AsyncModeProvider value={ true }> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose this could be |
||
<ListViewDropIndicator | ||
listViewRef={ elementRef } | ||
blockDropTarget={ blockDropTarget } | ||
|
@@ -141,12 +155,11 @@ function ListView( | |
<ListViewBranch | ||
blocks={ clientIdsTree } | ||
selectBlock={ selectEditorBlock } | ||
selectedBlockClientIds={ selectedClientIds } | ||
{ ...props } | ||
/> | ||
</ListViewContext.Provider> | ||
</TreeGrid> | ||
</> | ||
</AsyncModeProvider> | ||
); | ||
} | ||
export default forwardRef( ListView ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,25 +10,6 @@ import { useSelect } from '@wordpress/data'; | |
import { isClientIdSelected } from './utils'; | ||
import { store as blockEditorStore } from '../../store'; | ||
|
||
const useListViewSelectedClientIds = ( | ||
__experimentalPersistentListViewFeatures | ||
) => | ||
useSelect( | ||
( select ) => { | ||
const { | ||
getSelectedBlockClientId, | ||
getSelectedBlockClientIds, | ||
} = select( blockEditorStore ); | ||
|
||
if ( __experimentalPersistentListViewFeatures ) { | ||
return getSelectedBlockClientIds(); | ||
} | ||
|
||
return getSelectedBlockClientId(); | ||
}, | ||
[ __experimentalPersistentListViewFeatures ] | ||
); | ||
|
||
const useListViewClientIdsTree = ( | ||
blocks, | ||
selectedClientIds, | ||
|
@@ -76,13 +57,32 @@ export default function useListViewClientIds( | |
showOnlyCurrentHierarchy, | ||
__experimentalPersistentListViewFeatures | ||
) { | ||
const selectedClientIds = useListViewSelectedClientIds( | ||
__experimentalPersistentListViewFeatures | ||
const { selectedClientIds, draggedClientIds } = useSelect( | ||
( select ) => { | ||
const { | ||
getSelectedBlockClientId, | ||
getSelectedBlockClientIds, | ||
getDraggedBlockClientIds, | ||
} = select( blockEditorStore ); | ||
|
||
if ( __experimentalPersistentListViewFeatures ) { | ||
return { | ||
selectedClientIds: getSelectedBlockClientIds(), | ||
draggedClientIds: getDraggedBlockClientIds(), | ||
}; | ||
} | ||
|
||
return { | ||
selectedClientIds: getSelectedBlockClientId(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For other reviewers getSelectedBlockClientIds vs getSelectedBlockClientId |
||
draggedClientIds: getDraggedBlockClientIds(), | ||
}; | ||
}, | ||
[ __experimentalPersistentListViewFeatures ] | ||
); | ||
const clientIdsTree = useListViewClientIdsTree( | ||
blocks, | ||
selectedClientIds, | ||
showOnlyCurrentHierarchy | ||
); | ||
return { clientIdsTree, selectedClientIds }; | ||
return { clientIdsTree, selectedClientIds, draggedClientIds }; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be further enhanced using an
IntersectionObserver
.