Subscribe on changes!

[Bug] `undefined` attrs are not being passed

avatar
Jun 15th 2021

Version

3.1.1

Reproduction link

https://github.com/wenfangdu/vue-attrs-repro

Steps to reproduce

Please use the repro link, this behavior doesn't exist in v3.0.11.

What is expected?

Attrs with undefined are being passed.

What is actually happening?

Attrs with undefined are not being passed.

avatar
Jun 15th 2021

This makes attrs and props have a consistent behavior after https://github.com/vuejs/vue-next/issues/3288: you shouldn't differentiate the cases where undefined is explicitly passed vs the prop is missing

avatar
Jun 15th 2021

@posva Please pardon me, am I understanding consistency wrong? I've updated my repro, please have a look.

import { defineComponent } from 'vue'

export default defineComponent({
  inheritAttrs: false,
  props: {
    baz: String,
  },
  setup(props, { attrs }) {
    //          👇 logs { baz: undefined }
    console.log(props)
    //          👇 logs { foo: 'foo' }, NOT { foo: 'foo', bar: undefined }
    console.log(attrs)

    return () => <div>Comp</div>
  },
})
avatar
Jun 16th 2021

@posva Thanks for clarifying, another change I overlooked is the following, which caused the confusion, attaching it here for future reference:

BREAKING: No longer removes attribute if the value is boolean false. Instead, it's set as attr="false". To remove the attribute, use null or undefined.