From 344d0f48c6e2c26ff64ec3488223a9c1fb780e70 Mon Sep 17 00:00:00 2001 From: Marin Atanasov <8436925+tyxla@users.noreply.github.com> Date: Tue, 22 Oct 2024 17:06:23 +0300 Subject: [PATCH] ESLint: Fix a couple of React Compiler reassignment errors --- .../src/components/list-view/branch.js | 14 ++++++++------ .../block-library/src/table-of-contents/edit.js | 10 +++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/block-editor/src/components/list-view/branch.js b/packages/block-editor/src/components/list-view/branch.js index ebd1d5a36f570..5df7134e125cd 100644 --- a/packages/block-editor/src/components/list-view/branch.js +++ b/packages/block-editor/src/components/list-view/branch.js @@ -5,7 +5,7 @@ import { __experimentalTreeGridRow as TreeGridRow, __experimentalTreeGridCell as TreeGridCell, } from '@wordpress/components'; -import { memo } from '@wordpress/element'; +import { memo, useRef } from '@wordpress/element'; import { AsyncModeProvider, useSelect } from '@wordpress/data'; /** @@ -123,6 +123,8 @@ function ListViewBranch( props ) { draggedClientIds, } = useListViewContext(); + const nextPositionRef = useRef(); + if ( ! canParentExpand ) { return null; } @@ -133,7 +135,7 @@ function ListViewBranch( props ) { const blockCount = filteredBlocks.length; // The appender means an extra row in List View, so add 1 to the row count. const rowCount = showAppender ? blockCount + 1 : blockCount; - let nextPosition = listPosition; + nextPositionRef.current = listPosition; return ( <> @@ -141,7 +143,7 @@ function ListViewBranch( props ) { const { clientId, innerBlocks } = block; if ( index > 0 ) { - nextPosition += countBlocks( + nextPositionRef.current += countBlocks( filteredBlocks[ index - 1 ], expandedState, draggedClientIds, @@ -165,7 +167,7 @@ function ListViewBranch( props ) { } ); const { itemInView } = fixedListWindow; - const blockInView = itemInView( nextPosition ); + const blockInView = itemInView( nextPositionRef.current ); const position = index + 1; const updatedPath = @@ -218,7 +220,7 @@ function ListViewBranch( props ) { showBlockMovers={ showBlockMovers } path={ updatedPath } isExpanded={ isDragged ? false : shouldExpand } - listPosition={ nextPosition } + listPosition={ nextPositionRef.current } selectedClientIds={ selectedClientIds } isSyncedBranch={ syncedBranch } displacement={ displacement } @@ -239,7 +241,7 @@ function ListViewBranch( props ) { showBlockMovers={ showBlockMovers } level={ level + 1 } path={ updatedPath } - listPosition={ nextPosition + 1 } + listPosition={ nextPositionRef.current + 1 } fixedListWindow={ fixedListWindow } isBranchSelected={ isSelectedBranch } selectedClientIds={ selectedClientIds } diff --git a/packages/block-library/src/table-of-contents/edit.js b/packages/block-library/src/table-of-contents/edit.js index 121a8d7c8fc31..33d6e6896fb20 100644 --- a/packages/block-library/src/table-of-contents/edit.js +++ b/packages/block-library/src/table-of-contents/edit.js @@ -17,7 +17,7 @@ import { ToolbarGroup, } from '@wordpress/components'; import { useDispatch, useSelect } from '@wordpress/data'; -import { renderToString } from '@wordpress/element'; +import { renderToString, useRef } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { useInstanceId } from '@wordpress/compose'; import { store as noticeStore } from '@wordpress/notices'; @@ -59,14 +59,14 @@ export default function TableOfContentsEdit( { // If a user clicks to a link prevent redirection and show a warning. const { createWarningNotice, removeNotice } = useDispatch( noticeStore ); - let noticeId; + const noticeIdRef = useRef(); const showRedirectionPreventedNotice = ( event ) => { event.preventDefault(); // Remove previous warning if any, to show one at a time per block. - removeNotice( noticeId ); - noticeId = `block-library/core/table-of-contents/redirection-prevented/${ instanceId }`; + removeNotice( noticeIdRef.current ); + noticeIdRef.current = `block-library/core/table-of-contents/redirection-prevented/${ instanceId }`; createWarningNotice( __( 'Links are disabled in the editor.' ), { - id: noticeId, + id: noticeIdRef.current, type: 'snackbar', } ); };