Skip to content

Commit

Permalink
Navigation: Memoize link value passed to the LinkControl (WordPress#5…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka authored and sethrubenstein committed Jul 13, 2023
1 parent 14236f3 commit 039b770
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/block-library/src/navigation-link/link-ui.js
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import {
BlockIcon,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { createInterpolateElement } from '@wordpress/element';
import { createInterpolateElement, useMemo } from '@wordpress/element';
import { store as coreStore } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';
import { switchToBlockType } from '@wordpress/blocks';
@@ -154,11 +154,17 @@ export function LinkUI( props ) {
}

const { label, url, opensInNewTab, type, kind } = props.link;
const link = {
url,
opensInNewTab,
title: label && stripHTML( label ),
};

// Memoize link value to avoid overriding the LinkControl's internal state.
// This is a temporary fix. See https://github.com/WordPress/gutenberg/issues/50976#issuecomment-1568226407.
const link = useMemo(
() => ( {
url,
opensInNewTab,
title: label && stripHTML( label ),
} ),
[ label, opensInNewTab, url ]
);

return (
<Popover

0 comments on commit 039b770

Please sign in to comment.