Skip to content

Commit

Permalink
Revert native editor workaround for stale useSelect value
Browse files Browse the repository at this point in the history
Store updates triggered from within the post title component's
`componentDidUpdate` hook resulted in stale `isTitledSelected` values
returned from the memoized `useSelect`. This reverts a workaround that
avoided memoization by splitting the `useSelect` hook usage in two.
  • Loading branch information
dcalhoun committed Sep 14, 2022
1 parent 675f2b2 commit 3172233
Showing 1 changed file with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,24 @@ function useNativeBlockEditorSettings( settings, hasTemplate ) {
const editorSettings = useBlockEditorSettings( settings, hasTemplate );

const supportReusableBlock = capabilities.reusableBlock === true;
const { reusableBlocks } = useSelect(
( select ) => ( {
reusableBlocks: supportReusableBlock
? select( coreStore ).getEntityRecords(
'postType',
'wp_block',
// Unbounded queries are not supported on native so as a workaround, we set per_page with the maximum value that native version can handle.
// Related issue: https://github.com/wordpress-mobile/gutenberg-mobile/issues/2661
{ per_page: 100 }
)
: [],
} ),
const { reusableBlocks, isTitleSelected } = useSelect(
( select ) => {
return {
reusableBlocks: supportReusableBlock
? select( coreStore ).getEntityRecords(
'postType',
'wp_block',
// Unbounded queries are not supported on native so as a workaround, we set per_page with the maximum value that native version can handle.
// Related issue: https://github.com/wordpress-mobile/gutenberg-mobile/issues/2661
{ per_page: 100 }
)
: [],
isTitleSelected: select( editorStore ).isPostTitleSelected(),
};
},
[ supportReusableBlock ]
);

const { isTitleSelected } = useSelect( ( select ) => ( {
isTitleSelected: select( editorStore ).isPostTitleSelected(),
} ) );

return useMemo(
() => ( {
...editorSettings,
Expand Down

0 comments on commit 3172233

Please sign in to comment.