From e9347409c177d07be160f8e82184194fda8766e0 Mon Sep 17 00:00:00 2001 From: Amit Raj Date: Tue, 21 May 2024 17:48:56 +0530 Subject: [PATCH] Fix redundant link preview display when link text includes protocol in LinkControl. --- .../src/components/link-control/link-preview.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/block-editor/src/components/link-control/link-preview.js b/packages/block-editor/src/components/link-control/link-preview.js index 867b69356eb9d9..c22f0388797249 100644 --- a/packages/block-editor/src/components/link-control/link-preview.js +++ b/packages/block-editor/src/components/link-control/link-preview.js @@ -13,7 +13,11 @@ import { __experimentalTruncate as Truncate, } from '@wordpress/components'; import { useCopyToClipboard } from '@wordpress/compose'; -import { filterURLForDisplay, safeDecodeURI } from '@wordpress/url'; +import { + filterURLForDisplay, + safeDecodeURI, + removeProtocol, +} from '@wordpress/url'; import { Icon, globe, info, linkOff, edit, copySmall } from '@wordpress/icons'; import { __unstableStripHTML as stripHTML } from '@wordpress/dom'; import { useDispatch, useSelect } from '@wordpress/data'; @@ -59,6 +63,9 @@ export default function LinkPreview( { ! isEmptyURL && stripHTML( richData?.title || value?.title || displayURL ); + const isTitleRedundant = + value?.url && removeProtocol( displayTitle ) === displayURL; + let icon; if ( richData?.icon ) { @@ -112,7 +119,7 @@ export default function LinkPreview( { { displayTitle } - { value?.url && displayTitle !== displayURL && ( + { ! isTitleRedundant && ( { displayURL }