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.

input: JSX elements cannot have multiple attributes with the same name.

See original GitHub issue

The recent update made my build crash. The Error is:

ts(17001): JSX elements cannot have multiple attributes with the same name.

It’s an input whose type is either “radio” or “checkbox” with a v-model and a value. Obviously, those 2 are allowed for these types. Only for other inputs, it would be a duplication

<input type="myType" v-model="foo" :value="bar" />

defineProps({
  myType: {
    type: String as PropType<'radio' | 'checkbox'>
  }
}

Volar seems to handle this case as a regular input even tho the type of type (haha) is radio or checkbox.

Possible Solution

If you know that your input is a checkbox or radiobox, dont use v-model. Instead use :checked="foo" and @change="foo = $event.target.checked"

That will solve the duplication because volar seems to handle v-model as :value instead of :checked.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:22 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
Fuzzymacommented, Oct 13, 2022

@Fuzzyma you can use Show Virtual Files command to inspect for this.

Wow - I INSTANTLY found the issue when using this. In the virtual file, standalone attributes have the value (true). Unfortunetaly, using “true” instead of “null” didnt work either. Maybe because it is treated as a special value? I dont know. The empty string works and is fine for now

1reaction
Fuzzymacommented, Oct 12, 2022

We could simply allow passing an array:

  "vueCompilerOptions": {
    "experimentalModelPropName": {
      "": {
        "input": [
          { "type": "radio" },
          { "hack-ignore-vmodel": "" }
        ]
      },
      "checked": {
        "input": { "type": "checkbox" }
      },
      "value": {
        "input": true,
        "textarea": true,
        "select": true
      }
    },
  },
Read more comments on GitHub >

github_iconTop Results From Across the Web

Attempting to render to multiple attributes to a single JSX ...
I want to iterate through both arrays and render data from both to the same image element. I successfully iterated over a single...
Read more >
How to handle multiple attributes in ReactJS - Nikita Hlopov
You can store all of the attributes in an object and use Spread syntax on the element to assign them. render () {...
Read more >
Attributes that work differently between React and HTML
We can't use the attributes with the same name in both React and HTML because when the code is rendered in React, JSX...
Read more >
JSX In Depth - React
Specifying The React Element Type​​ The first part of a JSX tag determines the type of the React element. Capitalized types indicate that...
Read more >
jsx elements cannot have multiple attributes with the same name
jsx elements cannot have multiple attributes with the same name · Oops, You will need to install Grepper and log-in to perform this...
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