question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ESLint rule to enforce `key` property on tags inside `next/head`

See original GitHub issue

Describe the feature you’d like to request

The Next.js docs for the next/head component states the following:

To avoid duplicate tags in your head you can use the key property, which will make sure the tag is only rendered once.

The idea is to enforce this recommendation with an eslint rule to prevent potential bugs (duplicate tags) by spotting cases where a key property is missing from tags that live inside next/head.

Describe the solution you’d like

We would need to create new rule for eslint-plugin-next. I suggest the name next-head-key. Not sure if this should be an error or a warning.

The rule would check for the presence of a key prop on:

  • Direct children of the Head element,
  • Children that are wrapped into maximum one level of <React.Fragment>
  • Children that are wrapped into a top-level JSX array expression
  • Ignore the <title> element as it already gets deduped automatically

Here’s how I would implement something like this: https://github.com/vercel/next.js/compare/canary...etienne-martin:next.js:eslint-head-key

Describe alternatives you’ve considered

The temporary solution I came up with in a different project was to write a global mock for next/head that would throw if a key property is missing. Not ideal.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:6
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Enrique-Ambrociocommented, Oct 14, 2022

I see. No worries! If anything should ever come up please don’t hesitate to reach out to me. Also, if you by any chance come across potential opportunities, could you possibly let me know? Thank you! @etienne-martin

0reactions
etienne-martincommented, Oct 13, 2022

Hi @Enrique-Ambrocio, the issue is still open and we haven’t decided yet if we’re going to go forward with my suggestion. However, I see that @puneetkathar1 has already started working on it: https://github.com/vercel/next.js/pull/39975

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rules - ESLint - Pluggable JavaScript Linter
The "extends": "eslint:recommended" property in a configuration file enables ... Enforce return statements in callbacks of array methods ... no-dupe-keys.
Read more >
Ignoring ESLint - next.config.js
If you'd like Next.js to produce production code even when your application has ESLint errors, you can disable the built-in linting step completely....
Read more >
vercel/next.js
ESLint rule to enforce `key` property on tags inside `next/head`. good first issue. template: story. area: ESLint. Created 4 months ago | 5...
Read more >
Next.js Setup | ESLint Jest React Testing Library and Absolute ...
If you do, you can also omit the everything in the rules property. Personally, I like the extra structure and what's there feel...
Read more >
vue/max-attributes-per-line
Limits the maximum number of attributes/properties per line to ... This rule aims to enforce a number of attributes per line in templates....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found