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.

<component :is=".."> should not set attributes to the root html tag of the component automatically

See original GitHub issue

Version

2.5.2

Reproduction link

https://codesandbox.io/s/2oz1p5qpo0

Steps to reproduce

Open the reproduction link:

  1. Open the devtools
  2. The element with the id="foo" will have the propa attribute

What is expected?

The element with the id="foo" doesn’t have the propa attribute

What is actually happening?

It has.


I know the problem is that the Foo component doesn’t declare the props fields(I comment in the Foo component), if it has, the element with the id="foo" will not have the propa attribute, but the problem here is that the variable passed to is to <component :is="..."> it not determined, probably it is a component which don’t need the propA field.

So, we should not set any attribute to the root html tag of the component automatically.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Justineocommented, Sep 5, 2018

Seems not correct, only the component which related to native tag(almost are about form like input/button/video/audio/select/form/table…) will need this feature

Actually there are a lot of HTML global attributes which may need inheritAttrs to be true. For example, when you are making an accessible web app, the aria-* global attributes are essential and needs to be handcrafted differently in each scenario. It’s impossible to encapsulate all A11Y annotation inside component libraries.

That’s a workaround but seems not correct, it needs us to add some judgement like v-bind=“is === Foo ? { prop: ‘…’ } : {}”, why I need to do this? It just use a problem to solve another problem.

You can pass a component’s options object into is and filter the v-bind object by checking if it has specific prop declared for the rendered component. See this sandbox: https://codesandbox.io/s/42zoo8m4o7.

0reactions
NE-SmallTowncommented, Sep 5, 2018

Ok, fine, just trade off, though seems the codesandbox is more fussy than just use inheritAttrs IMO

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extraneous non-props attributes (...) were passed to ... - GitHub
I have met the same warning. The reason may be that you have more than one root node in the component template. Refer...
Read more >
Vue 3 passing array warning: Extraneous non-props attributes ...
The Message is: [Vue warn]: Extraneous non-props attributes (class) were passed to component but could not be automatically inherited ...
Read more >
Element.setAttribute() - Web APIs | MDN
Sets the value of an attribute on the specified element. If the attribute already exists, the value is updated; otherwise a new attribute...
Read more >
Build Advanced Components in Vue 3 using $attrs
A component property that holds all of the attribute, property, and custom events that are not currently defined within the component.
Read more >
Web component HTML layout - 4Js
In order to get a stretchable HTML content in your web component, start by defining the WEBCOMPONENT form field with the following attributes:...
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