Subscribe on changes!

v3.2.43: initial value of watcher changed from undefined to an empty array

avatar
Nov 9th 2022

Vue version

3.2.43

Link to minimal reproduction

https://sfc.vuejs.org/#eNp9UV1vnDAQ/Csrq1KIBLht+nTlUPLWH9C3ulIo7N25wR+yF04R4r9nMVx0SaQ84d2dnZkdJvHgfTkOKHaiIjS+bwhrZQGqoU9ffvUaxuLgwl6J9tTYI4K2QI6a/peO5MKzEvU0wTab50r2euWQiaSSV8xcxjZoTxCRBg89LzExRSZRVhvvAgGTOeMHwi6HgE1LesTldcjh3FB7ghkOwRm4Yec3PxfS1tlIqynYv25n2S3sa/j29ZZBV5DNNyOZs3oIoXmuIgVtj3Wd/fm7oJNOtlyxcqS9cmz6AfPUtXj+vfRycH2XXgk3raFdy6xbpR/iKXtMyC2rbr3iy3RhmHmPywv1/Lg4AZiT4gTaGOw057gDCgNHrewCqOSaKOcncrFGWJjGl/+js/xjkyW1DTjn3cWkEpzfUitxIvJxJ+Vg/dOx5PzkPc9kGCxpg0XnzP1d+b38cSc7Puq6X2I0xb/gzhEDKyqRzG7kkpsjhiKg7TBg+FTsHfaN4LvZB9EUk7KzmF8AXV35QQ==

Steps to reproduce

const total = computed(() => 10);
const totalHistory = ref<Array<string>>([]);
watch(
  () => total.value,
  (newTotal, oldTotal) => {
    totalHistory.value.push(`Total changed from ${oldTotal} to ${newTotal}`);
  },
  { immediate: true }
);

This used to log Total changed from undefined to 10 but now logs Total changed from to 10 as oldTotal is now an empty array.

Change the version to v3.2.42 to this the former behavior

What is expected?

The initial value should be undefined (or a breaking change should be added to the changelog to mention that it is now an empty array)

What is actually happening?

The initial value is an empty array

System Info

System:
    OS: macOS 12.6
    CPU: (10) arm64 Apple M1 Max
    Memory: 21.55 GB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.17.0 - ~/.volta/tools/image/node/16.17.0/bin/node
    Yarn: 1.22.17 - ~/.volta/tools/image/yarn/1.22.17/bin/yarn
    npm: 8.19.2 - ~/.volta/tools/image/npm/8.19.2/bin/npm
  Browsers:
    Chrome: 107.0.5304.87
    Firefox: 106.0.5
    Safari: 16.0
  npmPackages:
    vue: 3.2.43 => 3.2.43

Any additional comments?

No response