Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] undefined attrs are not being passed #3953

Closed
wenfangdu opened this issue Jun 15, 2021 · 3 comments
Closed

[Bug] undefined attrs are not being passed #3953

wenfangdu opened this issue Jun 15, 2021 · 3 comments

Comments

@wenfangdu
Copy link

wenfangdu commented Jun 15, 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.

@posva
Copy link
Member

posva commented Jun 15, 2021

This makes attrs and props have a consistent behavior after #3288: you shouldn't differentiate the cases where undefined is explicitly passed vs the prop is missing

@posva posva closed this as completed Jun 15, 2021
@wenfangdu
Copy link
Author

wenfangdu commented Jun 15, 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>
  },
})

@wenfangdu
Copy link
Author

wenfangdu commented Jun 16, 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.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants