Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next-eslint-plugin: aborts when facing a <Link><a/></Link> #26206

Closed
polesapart opened this issue Jun 16, 2021 · 3 comments
Closed

next-eslint-plugin: aborts when facing a <Link><a/></Link> #26206

polesapart opened this issue Jun 16, 2021 · 3 comments
Assignees
Labels
bug Issue was opened via the bug report template.

Comments

@polesapart
Copy link

polesapart commented Jun 16, 2021

What version of Next.js are you using?

11.0

What version of Node.js are you using?

14.16.1

What browser are you using?

N/A

What operating system are you using?

Linux

How are you deploying your application?

N/a

Describe the Bug

I have this on a tsx file:

const CustomLink = (props) => {
  const href = props.href
  const isInternalLink = href && (href.startsWith('/') || href.startsWith('#'))

  if (isInternalLink) {
    return (
      <Link href={href} passHref>
        <a {...props}/>
      </Link>
    )
  }

  return <a target="_blank" rel="noopener noreferrer" {...props} />
}

enabling eslint as document in next 11 fails with:

$ pnpx next lint Cannot read property 'name' of null Occurred while linting '...'/mdx-settings.tsx:13

Expected Behavior

next lint should work. In fact, changing the tag to:
<a {...props}></a>

works.

The offending code is in link-passhref.js:49:
const hasAnchorChild = children.some( (attr) => attr.type === 'JSXElement' && attr.openingElement.name.name === 'a' && attr.closingElement.name.name === 'a' )

To Reproduce

Put the above code in a new tsx file and follow next lint install instructions.

@polesapart polesapart added the bug Issue was opened via the bug report template. label Jun 16, 2021
@housseindjirdeh housseindjirdeh self-assigned this Jun 17, 2021
@housseindjirdeh
Copy link
Collaborator

Fixed in #26280

@NickCrews
Copy link
Contributor

Thanks for the great description of how to sidestep the bug @polesapart, and thanks @housseindjirdeh for the fix!

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

4 participants