Skip to content

findLinkFromClickTarget breaks for SVG <a> elements (SVGAnimatedString has no startsWith) #1510

@Samuel-Labagnere

Description

@Samuel-Labagnere

It looks like PR #1285 introduced a regression affecting SVG links (<a> elements inside <svg>).

Current implementation:

export function findLinkFromClickTarget(target) {
  const link = findClosestRecursively(target, "a[href], a[xlink\\:href]")

  if (!link) return null
  if (link.href.startsWith("#")) return null
  if (link.hasAttribute("download")) return null

  const linkTarget = link.getAttribute("target")
  if (linkTarget && linkTarget !== "_self") return null

  return link
}

Introduced change:

+ if (link.href.startsWith("#")) return null

SVGAElement does not expose href as a string, but as an SVGAnimatedString. Which does not implement startsWith().
However, both have access to getAttribute(), and getAttribute('href') consistently returns a string for both HTMLAnchorElement and SVGAElement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions