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

fix(runtime-core): watching multiple values - handle undefined as initial values (fix: #5032) #5033

Merged
merged 3 commits into from Oct 20, 2022

Conversation

LinusBorg
Copy link
Member

We currently have an empty array as the intial oldValue for a watcher that watches multiple values.

This does fail for an edge case where we watch multiple values and all of them are initially undefined, and trigger the watcher immediately.

We can solve this by settting the initial oldValue to an array filled with INITIAL_WATCHER_VALUE

fix: #5032

@nickrum
Copy link

nickrum commented Jun 14, 2022

I ran into the exact same issue this PR is fixing. While investigationg the issue, in noticed that, in addition to the original issue, the wrong value is passed to callWithAsyncErrorHandling() when using an immediate watcher with multiple sources over here.

Replacing oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue with something like (isMultiSource ? (oldValue as []).every((v) => v === INITIAL_WATCHER_VALUE) : oldValue === INITIAL_WATCHER_VALUE) ? undefined : oldValue should fix the issue.

It's a pretty minor issue, so I'm wondering whether this would warrant a separate PR or if you could simply include the fix in your PR.

watch(
[a, b],
() => {
called = true
Copy link
Member

Choose a reason for hiding this comment

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

The test seems not testing the change?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right , I'm only testing it's being called initially (which previously it wasn't) but I need to validate the arguments passed.

That actually made me find a part my fix did not cover - oldValue was not undefined when it should be.

@netlify
Copy link

netlify bot commented Oct 7, 2022

Deploy Preview for vuejs-coverage failed.

Name Link
🔨 Latest commit 1bff8c1
🔍 Latest deploy log https://app.netlify.com/sites/vuejs-coverage/deploys/633fff8c02245c0008f04572

@zhangbowy
Copy link

ant-design-vue fixed this vueComponent/ant-design-vue#6085

chrislone pushed a commit to chrislone/core that referenced this pull request Feb 4, 2023
zhangzhonghe pushed a commit to zhangzhonghe/core that referenced this pull request Apr 12, 2023
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.

Watch handler is not immediately called when setup with multiple sources all having an undefined value
4 participants