Skip to content

Commit

Permalink
Try controlled page list block (#46416)
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan authored Dec 15, 2022
1 parent 5475424 commit 3331ee1
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions packages/block-library/src/page-list/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
Button,
} from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { useMemo, useState, useEffect } from '@wordpress/element';
import { useMemo, useState } from '@wordpress/element';
import { useEntityRecords } from '@wordpress/core-data';
import { useSelect, useDispatch } from '@wordpress/data';

Expand All @@ -39,6 +39,7 @@ import { convertDescription } from './constants';
// We only show the edit option when page count is <= MAX_PAGE_COUNT
// Performance of Navigation Links is not good past this value.
const MAX_PAGE_COUNT = 100;
const NOOP = () => {};

export default function PageListEdit( {
context,
Expand All @@ -49,8 +50,6 @@ export default function PageListEdit( {
const { parentPageID } = attributes;
const [ pages ] = useGetPages();
const { pagesByParentId, totalPages, hasResolvedPages } = usePageData();
const { replaceInnerBlocks, __unstableMarkNextChangeAsNotPersistent } =
useDispatch( blockEditorStore );

const isNavigationChild = 'showSubmenuIcon' in context;
const allowConvertToLinks =
Expand Down Expand Up @@ -133,6 +132,9 @@ export default function PageListEdit( {
renderAppender: false,
__unstableDisableDropZone: true,
templateLock: 'all',
onInput: NOOP,
onChange: NOOP,
value: blockList,
} );

const getBlockContent = () => {
Expand Down Expand Up @@ -185,13 +187,6 @@ export default function PageListEdit( {
}
};

useEffect( () => {
__unstableMarkNextChangeAsNotPersistent();
if ( blockList ) {
replaceInnerBlocks( clientId, blockList );
}
}, [ clientId, blockList ] );

const { replaceBlock, selectBlock } = useDispatch( blockEditorStore );

const { parentNavBlockClientId } = useSelect( ( select ) => {
Expand Down

0 comments on commit 3331ee1

Please sign in to comment.