Skip to content

Commit

Permalink
Merge pull request #1751 from tomusborne/fix/query-re-rendering
Browse files Browse the repository at this point in the history
Fix: Query re-rendering on auto-save
  • Loading branch information
tomusborne authored Feb 3, 2025
2 parents 937445f + 2b796f9 commit 2f6ebff
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/blocks/looper/components/LoopInnerBlocksRenderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ function BlockPreview( { blocks, isHidden } ) {
const MemoizedBlockPreview = memo( BlockPreview );

function useWpQuery( shouldRequest = true, { query, attributes, selectedBlock, context, queryType } ) {
const currentPost = useSelect( ( select ) => {
const { currentPostId, currentPostAuthor } = useSelect( ( select ) => {
const { getCurrentPost } = select( 'core/editor' );

return getCurrentPost ? getCurrentPost() : null;
const currentPost = getCurrentPost ? getCurrentPost() : null;
return {
currentPostId: currentPost?.id,
currentPostAuthor: currentPost?.author,
};
} );

const {
Expand Down Expand Up @@ -89,8 +92,8 @@ function useWpQuery( shouldRequest = true, { query, attributes, selectedBlock, c
context,
queryType,
block: selectedBlock,
postId: currentPost?.id,
authorId: currentPost?.author,
postId: currentPostId,
authorId: currentPostAuthor,
},
} );

Expand All @@ -104,7 +107,7 @@ function useWpQuery( shouldRequest = true, { query, attributes, selectedBlock, c
}

fetchPosts();
}, [ query, currentPost ] );
}, [ query, currentPostId, currentPostAuthor ] );

const result = { data, isResolvingData: isLoading, hasResolvedData: data?.length > 0 };

Expand Down

0 comments on commit 2f6ebff

Please sign in to comment.