Skip to content

Prop not updated when immediate watcher accessing it (async mode) #1140

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

Open
rndmerle opened this issue Feb 8, 2019 · 7 comments
Open

Prop not updated when immediate watcher accessing it (async mode) #1140

rndmerle opened this issue Feb 8, 2019 · 7 comments
Labels

Comments

@rndmerle
Copy link

rndmerle commented Feb 8, 2019

Version

1.0.0-beta.29

Reproduction link

https://github.com/rndmerle/repro-vue-test-utils-sync/tree/setprops-watcher

Steps to reproduce

git clone -b setprops-watcher https://github.com/rndmerle/repro-vue-test-utils-sync.git

yarn && yarn test

What is expected?

Hello test passing, with logging on console:

foo undefined
foo xxx

What is actually happening?

Hello test not passing, with logging on console:

foo undefined

To make the test pass, either:

  • switch immediate to false (and uncomment created() content)
  • change the watcher handler function to make anything as long it's not accessing the foo prop
@eddyerburgh eddyerburgh added the bug label Feb 8, 2019
@BrianBrenner
Copy link

I'm getting this as well. This occurs also even if you aren't watching the prop directly, but are watching a computed prop that uses the prop. I made an example repo off of yours, install instructions are the same:

https://github.com/DoubleB123/repro-vue-test-utils-sync/tree/computed

@Mighty683
Copy link

Mighty683 commented May 13, 2019

I also occured this bug when watch for prop change after call setProps watcher isn't called

@Dayna-A
Copy link

Dayna-A commented Jul 17, 2019

I am having this same issue, has anyone found a successful workaround?

@xanf
Copy link
Contributor

xanf commented Sep 2, 2019

I found the core reason for that :)

When we have component with watcher for immediate: true watcher Vue dependency system will track dependency from our component to parent component, which renders our own one. This effectively means, that as soon as we explicitly set prop on the component with setProps - our component will be immediately re-rendered with original props by our parent component

I've created #1300 to address this issue and added original failed test

@rndmerle
Copy link
Author

rndmerle commented Sep 2, 2019

Nice find!

@bugy
Copy link
Contributor

bugy commented Oct 19, 2019

@Dayna-A and everyone looking for a workaround,
for me calling the following code worked, after mounting a component:

    wrapper = mount(MyComponent, options);
    wrapper.vm.$parent.$forceUpdate();
    await wrapper.vm.$nextTick();

I'm initializing the component in

beforeEach(async function () {

(please note async)

@dsvanidze
Copy link

@bugy Thank you! This solved my problem with setProps()!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants