From 285da75a6b86c6fc123c4762ee04e1840de7853e Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Mon, 27 Nov 2023 11:29:37 +1000 Subject: [PATCH 1/2] Design Tools: Fix last ToolsPanelItem styling --- .../src/tools-panel/tools-panel-item/hook.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/components/src/tools-panel/tools-panel-item/hook.ts b/packages/components/src/tools-panel/tools-panel-item/hook.ts index 23701afdfcfd0..244349b6379ea 100644 --- a/packages/components/src/tools-panel/tools-panel-item/hook.ts +++ b/packages/components/src/tools-panel/tools-panel-item/hook.ts @@ -2,7 +2,12 @@ * WordPress dependencies */ import { usePrevious } from '@wordpress/compose'; -import { useCallback, useEffect, useMemo } from '@wordpress/element'; +import { + useCallback, + useEffect, + useLayoutEffect, + useMemo, +} from '@wordpress/element'; /** * Internal dependencies @@ -59,7 +64,11 @@ export function useToolsPanelItem( // Registering the panel item allows the panel to include it in its // automatically generated menu and determine its initial checked status. - useEffect( () => { + // + // This is performed in a layout effect to ensure that the panel item + // is registered before it is rendered preventing a rendering glitch. + // See: https://github.com/WordPress/gutenberg/issues/56470 + useLayoutEffect( () => { if ( hasMatchingPanel && previousPanelId !== null ) { registerPanelItem( { hasValue: hasValueCallback, From 0382f569d72b0e48b0f1bf48f752a7c45d3725ee Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Mon, 27 Nov 2023 11:44:39 +1000 Subject: [PATCH 2/2] Add changelog --- packages/components/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index 0f60b1aaee51a..89dfdf8cdfc13 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -6,6 +6,10 @@ - `Button`: Add focus rings to focusable disabled buttons ([#56383](https://github.com/WordPress/gutenberg/pull/56383)). +### Bug Fix + +- `ToolsPanelItem`: Use useLayoutEffect to prevent rendering glitch for last panel item styling. ([#56536](https://github.com/WordPress/gutenberg/pull/56536)). + ### Experimental - `Tabs`: Memoize and expose the component context ([#56224](https://github.com/WordPress/gutenberg/pull/56224)).