From 73a854dfe985b908e3a26c7a7acbe26b56707d83 Mon Sep 17 00:00:00 2001 From: Khokan Sardar Date: Mon, 24 Aug 2026 08:08:30 +0530 Subject: [PATCH 1/3] Embeds: Handle deeply nested links in the embed click handler. The click handler in the embed template only looked for an `href` on the event target and its immediate parent, so link text wrapped more than one element deep resolved to no href and the link opened inside the embed iframe instead of the parent window. Use `closest( '[href]' )` to walk the full ancestor chain instead. This also removes a `TypeError` thrown when the click target has no parent element. Fixes #65947. --- src/js/_enqueues/lib/embed-template.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/js/_enqueues/lib/embed-template.js b/src/js/_enqueues/lib/embed-template.js index ae58e4e967d7a..9913d286a3e6e 100644 --- a/src/js/_enqueues/lib/embed-template.js +++ b/src/js/_enqueues/lib/embed-template.js @@ -156,13 +156,8 @@ * Detect clicks to external (_top) links. */ function linkClickHandler( e ) { - var target = e.target, - href; - if ( target.hasAttribute( 'href' ) ) { - href = target.getAttribute( 'href' ); - } else { - href = target.parentElement.getAttribute( 'href' ); - } + var link = e.target.closest( '[href]' ), + href = link ? link.getAttribute( 'href' ) : null; // Only catch clicks from the primary mouse button, without any modifiers. if ( event.altKey || event.ctrlKey || event.metaKey || event.shiftKey ) { From cc597bac57763bfde65ba2c61351462fb71fe949 Mon Sep 17 00:00:00 2001 From: Khokan Sardar Date: Thu, 27 Aug 2026 17:57:17 +0530 Subject: [PATCH 2/3] Embeds: Resolve embed link clicks via the href property. The href DOM property resolves to an absolute URL against the embed document, which the parent window requires. Reading the attribute returned the value verbatim, so a relative link threw in the parent's `new URL()` call and the click dead-ended after `preventDefault()`. Elements whose href is not a string, such as SVG anchors, are skipped. --- src/js/_enqueues/lib/embed-template.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/js/_enqueues/lib/embed-template.js b/src/js/_enqueues/lib/embed-template.js index 9913d286a3e6e..b84678cb9d060 100644 --- a/src/js/_enqueues/lib/embed-template.js +++ b/src/js/_enqueues/lib/embed-template.js @@ -156,8 +156,12 @@ * Detect clicks to external (_top) links. */ function linkClickHandler( e ) { + /* + * The href property resolves to an absolute URL, which the parent window requires. + * Elements whose href is not a string, such as SVG anchors, are skipped. + */ var link = e.target.closest( '[href]' ), - href = link ? link.getAttribute( 'href' ) : null; + href = link && 'string' === typeof link.href ? link.href : null; // Only catch clicks from the primary mouse button, without any modifiers. if ( event.altKey || event.ctrlKey || event.metaKey || event.shiftKey ) { From 4c1f9d7f4d748dc4a3a4c130d351a03f8f3c4885 Mon Sep 17 00:00:00 2001 From: Khokan Sardar Date: Fri, 28 Aug 2026 09:37:30 +0530 Subject: [PATCH 3/3] Embeds: Use optional chaining for the resolved link href. Optional chaining is supported in every browser WordPress supports and is already used in non-transpiled core files, so the explicit ternary guard against a missing link is unnecessary. The string type check remains, so elements whose href is not a string, such as SVG anchors, are still skipped. --- src/js/_enqueues/lib/embed-template.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/_enqueues/lib/embed-template.js b/src/js/_enqueues/lib/embed-template.js index b84678cb9d060..82b7c6c4bda89 100644 --- a/src/js/_enqueues/lib/embed-template.js +++ b/src/js/_enqueues/lib/embed-template.js @@ -161,7 +161,7 @@ * Elements whose href is not a string, such as SVG anchors, are skipped. */ var link = e.target.closest( '[href]' ), - href = link && 'string' === typeof link.href ? link.href : null; + href = 'string' === typeof link?.href ? link.href : null; // Only catch clicks from the primary mouse button, without any modifiers. if ( event.altKey || event.ctrlKey || event.metaKey || event.shiftKey ) {