Subscribe on changes!

Inconstant `inheritAttrs` behavior in production and development

avatar
Nov 3rd 2020

Version

3.0.2

Reproduction link

https://github.com/07akioni/vue-inherit-attrs-bug

Steps to reproduce

  1. npm run dev image

  2. npm run build, then serve dist image

What is expected?

I'm not sure which is expected by vue. I expect the dev behavior

What is actually happening?

behavior is inconstant

avatar
Nov 3rd 2020

I'd rather say that the dev behaviour is wrong.

  • slots return a fragment,
  • and as the component has the slot as it's root node, it returns a fragment
  • and attribute inheritance is not supported on fragments.

However in dev, components can "accidentally return a fragment if they have one root node but also one or more root comments, which are preserved in dev, but not in prod.

So in dev, we "pull out" this root node from the fragment - and in this instance, that should not happen as no comments are involved.

Relevant code:

https://github.com/vuejs/vue-next/blob/f28ca556925147bb109d5ba77c5dafaf17d57322/packages/runtime-core/src/componentRenderUtils.ts#L216-L247

That function should not be called on a fragment resulting from a slot, or maybe check for actual Comment nodes to be present - not sure yet about the best approach.

avatar
Nov 9th 2020

Why attribute inheritance is not supported on fragments,is it limited by the difficulty of implementation? @LinusBorg

avatar
Nov 9th 2020

Because its unclear on which element to inherit.

  • Only the first one?
  • Or all?

The latter would create invalid HTML for an id attribute, for example, but it could be useful for a class.

avatar
Nov 9th 2020

I got it, thx.