Skip to content

Replace require-v-for-key with new rule just for stateful elements #522

Open
@chrisvfritz

Description

@chrisvfritz

The Problem

A lot of users get upset when the linter yells at them for not providing a key when it doesn't create a real problem and Vue itself doesn't complain. The real intent with this rule is to maintain object constancy to avoid:

  • Losing state in non-functional components (e.g. data properties being reset, lifecycle methods being re-run unnecessarily)
  • Losing state in stateful non-component elements such as input, select, etc (e.g. value being lost if not passed as a prop)
  • Visual inconsistencies on elements wrapped by <transition> or <transition-group> elements.

Potential Solution

To make everyone happy, I'm wondering if we may want to rename require-v-for-key to something like require-v-for-key-stateful-elements, then change its behavior so that it only gives a warning on:

  • Components
  • Stateful non-component elements
  • Non-stateful elements that use v-html
  • Non-stateful elements that contain any of the above
  • Non-stateful elements whose parent element is <transition> or <transition-group>.

Thoughts?

I'd like to get some other people weighing in on this before making the change, as there may be other cases I'm not considering.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions