From 4da3649b159605ac5678694c65db3ba7af1f880d Mon Sep 17 00:00:00 2001 From: Klaas Landsman Date: Sun, 6 Feb 2022 21:53:03 +0100 Subject: [PATCH] Fix detection of anchor click events inside svg (#23272) ## Bug The `nodeName` of an anchor inside an SVG equals the lowercase `a` instead of the html anchor's uppercase `A`. This behavior can be seen in this plain js demo: https://jsfiddle.net/L2p8f4ve/28/ fixes #23252 ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. ## Documentation / Examples - [ ] Make sure the linting passes Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com> --- packages/next/client/link.tsx | 5 +++- .../client-navigation/pages/nav/index.js | 23 +++++++++++++-- .../client-navigation/test/index.test.js | 29 ++++++++++++++++--- test/lib/browsers/base.ts | 11 ++++++- test/lib/browsers/playwright.ts | 16 ++++++++++ 5 files changed, 76 insertions(+), 8 deletions(-) diff --git a/packages/next/client/link.tsx b/packages/next/client/link.tsx index 13ca9d9844422f1..2aba7f79139d8b8 100644 --- a/packages/next/client/link.tsx +++ b/packages/next/client/link.tsx @@ -86,7 +86,10 @@ function linkClicked( ): void { const { nodeName } = e.currentTarget - if (nodeName === 'A' && (isModifiedEvent(e) || !isLocalURL(href))) { + // anchors inside an svg have a lowercase nodeName + const isAnchorNodeName = nodeName.toUpperCase() === 'A' + + if (isAnchorNodeName && (isModifiedEvent(e) || !isLocalURL(href))) { // ignore click for browser’s default behavior return } diff --git a/test/integration/client-navigation/pages/nav/index.js b/test/integration/client-navigation/pages/nav/index.js index 7326eaf577e0a55..bf4abf1646acfe7 100644 --- a/test/integration/client-navigation/pages/nav/index.js +++ b/test/integration/client-navigation/pages/nav/index.js @@ -78,14 +78,33 @@ export default class extends Component { - A element with onClick + An element with onClick - A element with target + An element with target + + + + + + + + +