Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Revert changes to QueryContent
  • Loading branch information
mikachan committed Sep 9, 2024
commit 13bfbcc2083926d8858f816cd904f52eb0af3396
24 changes: 5 additions & 19 deletions packages/block-library/src/query/edit/query-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { useSelect, useDispatch } from '@wordpress/data';
import { useInstanceId } from '@wordpress/compose';
import { useEffect, useCallback } from '@wordpress/element';
import { useEffect } from '@wordpress/element';
import {
BlockControls,
InspectorControls,
Expand Down Expand Up @@ -76,11 +76,6 @@ export default function QueryContent( {
// resetting again, so we need to mark these changes as not persistent
// with `__unstableMarkNextChangeAsNotPersistent`.

const updateQuery = useCallback(
( newQuery ) => setAttributes( { query: { ...query, ...newQuery } } ),
[ query, setAttributes ]
);

// Changes in query property (which is an object) need to be in the same callback,
// because updates are batched after the render and changes in different query properties
// would cause to override previous wanted changes.
Expand All @@ -97,26 +92,17 @@ export default function QueryContent( {
__unstableMarkNextChangeAsNotPersistent();
updateQuery( newQuery );
}
}, [
query,
postsPerPage,
inherit,
__unstableMarkNextChangeAsNotPersistent,
updateQuery,
] );
}, [ query.perPage, postsPerPage, inherit ] );
// We need this for multi-query block pagination.
// Query parameters for each block are scoped to their ID.
useEffect( () => {
if ( ! Number.isFinite( queryId ) ) {
__unstableMarkNextChangeAsNotPersistent();
setAttributes( { queryId: instanceId } );
}
}, [
queryId,
instanceId,
__unstableMarkNextChangeAsNotPersistent,
setAttributes,
] );
}, [ queryId, instanceId ] );
const updateQuery = ( newQuery ) =>
setAttributes( { query: { ...query, ...newQuery } } );
const updateDisplayLayout = ( newDisplayLayout ) =>
setAttributes( {
displayLayout: { ...displayLayout, ...newDisplayLayout },
Expand Down