Skip to content

fix: destructure attrs from context keep reactive, close #264 #594

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

Merged
merged 1 commit into from
Dec 7, 2020

Conversation

antfu
Copy link
Member

@antfu antfu commented Nov 22, 2020

No description provided.

Copy link
Member

@pikax pikax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has a limitation is added $attrs are not updated

 it('attrs should be reactive after destructuring', async () => {
    let _attrs: SetupContext['attrs'] = undefined!
    const foo = ref({ foo: 'bar' })

    const ComponentA = defineComponent({
      setup(_, { attrs }) {
        _attrs = attrs
      },
      template: `<div>{{$attrs}}</div>`,
    })
    const Root = defineComponent({
      components: {
        ComponentA,
      },
      setup() {
        return { foo }
      },
      template: `
        <ComponentA v-bind="foo"/>
      `,
    })

    const xxx = createApp(Root).mount()
    if (xxx) {
      debugger
    }

    expect(_attrs).toBeDefined()
    expect(_attrs.foo).toBe('bar')
    expect(_attrs.other).not.toBeDefined()

    foo.value.foo = 'bar2'
    //@ts-ignore
    foo.value.other = 'other'

    await nextTick()

    expect(_attrs.foo).toBe('bar2')
    expect(_attrs.other).toBe('other') // not working
  })

@antfu
Copy link
Member Author

antfu commented Nov 23, 2020

Yes. But I don't think it can be fixed without Proxy. I should update the docs about the caveat, or do you have any idea on this?

@pikax
Copy link
Member

pikax commented Nov 24, 2020

I also tried a few was to fix this but without success, add a caveat to the docs should be enough

@antfu antfu merged commit 4eecd66 into vuejs:master Dec 7, 2020
@antfu antfu deleted the fix/264 branch December 7, 2020 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants