Skip to content
Gx
GitHub

GX2022: two attributes with one name on one element

The tag of an element has two attributes with the same name.

Cause

The render writes one attribute for each name, and the last one wins. The first attribute of the tag then has no effect.

Gx gives no finding for two class attributes or two style attributes: their values join. A spread can also set an attribute of the tag, and its value replaces the value of the tag when the spread comes later.

Example

search/Search.gx
package search

<form>
  <input name="q" aria-label="Search" name="query">
</form>

gx check reports:

gx check
search/Search.gx:4:3: GX2022: the <input> has two name attributes: the render writes the last one

Fix

  1. Remove one of the two attributes.
  2. To let a caller change an attribute, put the spread after it: <input name="q" {...p.Attrs}>.