Embeds: Handle deeply nested links in the embed click handler - #13244
Embeds: Handle deeply nested links in the embed click handler#13244itzmekhokan wants to merge 1 commit into
Conversation
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.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
peterwilsoncc
left a comment
There was a problem hiding this comment.
Thanks for the pull request, this looks good to me.
I've tested various scenarios using jsbin and your updated code will behave as expected.
Clicking a link in a post embed opens it inside the embed iframe instead of the parent window when the link text is wrapped more than one element deep, for example
<a href="..."><span><span>Link text</span></span></a>.linkClickHandler()insrc/js/_enqueues/lib/embed-template.jsreadhreffrom the click target and, failing that, from its immediate parent only, so anything nested deeper resolved to no href. It now usesclosest( '[href]' )to walk the full ancestor chain, keeping the same attribute semantics.The change is strictly widening — direct and single-level-nested links resolve exactly as before — and it also removes a
TypeErrorthrown when the click target has no parent element.Trac ticket: https://core.trac.wordpress.org/ticket/65947
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: Diagnosing the DOM traversal bug, drafting the fix, and verifying link resolution against a real DOM. All changes were reviewed and validated by me.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.