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 #7071

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/runtime-core/__tests__/apiWatch.spec.ts
Expand Up @@ -186,7 +186,7 @@ describe('api: watch', () => {
(newVal, oldVal) => {
called = true
expect(newVal).toMatchObject([undefined, undefined])
expect(oldVal).toBeUndefined()
expect(oldVal).toMatchObject([undefined, undefined])
},
{ immediate: true }
)
Expand Down
4 changes: 3 additions & 1 deletion packages/runtime-core/src/apiWatch.ts
Expand Up @@ -335,7 +335,9 @@ function doWatch(
// pass undefined as the old value when it's changed for the first time
oldValue === INITIAL_WATCHER_VALUE ||
(isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE)
? undefined
? isMultiSource
? new Array((source as []).length).fill(undefined)
: undefined
: oldValue,
onCleanup
])
Expand Down