Skip to content

Commit

Permalink
Fix undo/redo 'trap' in navigation link block (#34565)
Browse files Browse the repository at this point in the history
* Mark side effecty code as not persistent change

* Add comment
  • Loading branch information
talldan authored Sep 7, 2021
1 parent f2de298 commit 45fe61e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -354,8 +357,14 @@ export default function NavigationLinkEdit( {
[ clientId ]
);

// Store the colors from context as attributes for rendering
useEffect( () => setAttributes( { isTopLevelLink } ), [ isTopLevelLink ] );
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 ] );

/**
* Insert a link block when submenu is added.
Expand Down

0 comments on commit 45fe61e

Please sign in to comment.