From f483b3b852a7736cb157e50b8d8a258cd8180a9a Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Mon, 6 Sep 2021 12:58:51 +0800 Subject: [PATCH 1/2] Mark side effecty code as not persistent change --- packages/block-library/src/navigation-link/edit.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/navigation-link/edit.js b/packages/block-library/src/navigation-link/edit.js index fa93ace9b5de5..95a60fbbb61f4 100644 --- a/packages/block-library/src/navigation-link/edit.js +++ b/packages/block-library/src/navigation-link/edit.js @@ -291,7 +291,10 @@ export default function NavigationLinkEdit( { }; const { showSubmenuIcon } = context; const { saveEntityRecord } = useDispatch( coreStore ); - const { insertBlock } = useDispatch( blockEditorStore ); + const { + insertBlock, + __unstableMarkNextChangeAsNotPersistent, + } = useDispatch( blockEditorStore ); const [ isLinkOpen, setIsLinkOpen ] = useState( false ); const listItemRef = useRef( null ); const isDraggingWithin = useIsDraggingWithin( listItemRef ); @@ -354,8 +357,10 @@ export default function NavigationLinkEdit( { [ clientId ] ); - // Store the colors from context as attributes for rendering - useEffect( () => setAttributes( { isTopLevelLink } ), [ isTopLevelLink ] ); + useEffect( () => { + __unstableMarkNextChangeAsNotPersistent(); + setAttributes( { isTopLevelLink } ); + }, [ isTopLevelLink ] ); /** * Insert a link block when submenu is added. From 48cb892cd04d7dd9dcbed182072a30b132065fc7 Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Mon, 6 Sep 2021 13:16:13 +0800 Subject: [PATCH 2/2] Add comment --- packages/block-library/src/navigation-link/edit.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/block-library/src/navigation-link/edit.js b/packages/block-library/src/navigation-link/edit.js index 95a60fbbb61f4..fce0a339b2e25 100644 --- a/packages/block-library/src/navigation-link/edit.js +++ b/packages/block-library/src/navigation-link/edit.js @@ -358,6 +358,10 @@ export default function NavigationLinkEdit( { ); useEffect( () => { + // This side-effect should not create an undo level as those should + // only be created via user interactions. Mark this change as + // not persistent to avoid undo level creation. + // See https://github.com/WordPress/gutenberg/issues/34564. __unstableMarkNextChangeAsNotPersistent(); setAttributes( { isTopLevelLink } ); }, [ isTopLevelLink ] );