Skip to content
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

[DO NOT MERGE] Debug stale useSelect value #33081

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion packages/data/src/components/use-select/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ const renderQueue = createQueue();
*
* @return {Function} A custom react hook.
*/
export default function useSelect( _mapSelect, deps ) {
export default function useSelect( _mapSelect, deps, { debug } = {} ) {
function debugLog( ...args ) {
if ( debug ) {
console.log( ...args );
}
}
const isWithoutMapping = typeof _mapSelect !== 'function';

if ( isWithoutMapping ) {
Expand Down Expand Up @@ -194,6 +199,7 @@ export default function useSelect( _mapSelect, deps ) {
return;
}
latestMapOutput.current = newMapOutput;
debugLog( '> useSelect: UPDATE', latestMapOutput.current );
} catch ( error ) {
latestMapOutputError.current = error;
}
Expand Down Expand Up @@ -229,5 +235,6 @@ export default function useSelect( _mapSelect, deps ) {
};
}, [ registry, trapSelect, depsChangedFlag, isWithoutMapping ] );

debugLog( '> useSelect: RETURN', mapOutput );
return isWithoutMapping ? registry.select( _mapSelect ) : mapOutput;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,29 @@ 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 }
)
: [],
} ),
[ supportReusableBlock ]
const { reusableBlocks, isTitleSelected } = useSelect(
( select ) => {
console.log( '> INSIDE useSelect', {
isTitleSelected: select( editorStore ).isPostTitleSelected(),
} );
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 ],
{ debug: true }
);

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

return useMemo(
() => ( {
Expand Down