From 3100d5e2f85c31bfb6e30a92a82bb8fba3cccd7c Mon Sep 17 00:00:00 2001 From: dhruvang21 <105810308+dhruvang21@users.noreply.github.com> Date: Fri, 11 Oct 2024 09:06:47 +0530 Subject: [PATCH] Fix: pattern rendering issue (#66022) When navigating between the "All Patterns" tab (specifically on page 2) and the "Template Parts" tab, the patterns fail to load correctly, and a "No Results" message is displayed. This commit checks for a previous post type, and, if different, resets the pagination to page 1 to ensure the first page of new post types are shown. --------- Co-authored-by: dhruvang21 Co-authored-by: ramonjd Co-authored-by: talldan --- packages/edit-site/src/components/page-patterns/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/edit-site/src/components/page-patterns/index.js b/packages/edit-site/src/components/page-patterns/index.js index be3bb7429c32f9..69ebf66093806a 100644 --- a/packages/edit-site/src/components/page-patterns/index.js +++ b/packages/edit-site/src/components/page-patterns/index.js @@ -78,6 +78,7 @@ export default function DataviewsPatterns() { const categoryId = categoryIdFromURL || PATTERN_DEFAULT_CATEGORY; const [ view, setView ] = useState( DEFAULT_VIEW ); const previousCategoryId = usePrevious( categoryId ); + const previousPostType = usePrevious( type ); const viewSyncStatus = view.filters?.find( ( { field } ) => field === 'sync-status' )?.value; @@ -121,10 +122,10 @@ export default function DataviewsPatterns() { // Reset the page number when the category changes. useEffect( () => { - if ( previousCategoryId !== categoryId ) { + if ( previousCategoryId !== categoryId || previousPostType !== type ) { setView( ( prevView ) => ( { ...prevView, page: 1 } ) ); } - }, [ categoryId, previousCategoryId ] ); + }, [ categoryId, previousCategoryId, previousPostType, type ] ); const { data, paginationInfo } = useMemo( () => { // Search is managed server-side as well as filters for patterns. // However, the author filter in template parts is done client-side.