vuejs / core

🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
https://vuejs.org/
MIT License
47.48k stars 8.3k forks source link

Iteration on array in event handler function #12232

Open Ericlm opened 1 week ago

Ericlm commented 1 week ago

Vue version

3.5.12

Link to minimal reproduction

https://github.com/Ericlm/vue-for-of

Steps to reproduce

What is expected?

Using a for loop (which could be for-of, for, or forEach) should not make any item "disappear" for the original array.

What is actually happening?

The for loop looks empty, or filled with undefined. For example, with an array of 5 numbers, it can print 5 undefined.

image

System Info

System:
    OS: macOS 15.0.1
    CPU: (8) arm64 Apple M1
    Memory: 88.38 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.6.0 - ~/.asdf/installs/nodejs/22.6.0/bin/node
    npm: 10.8.3 - ~/.asdf/plugins/nodejs/shims/npm
    pnpm: 9.9.0 - ~/.asdf/installs/nodejs/22.6.0/bin/pnpm
  Browsers:
    Chrome: 129.0.6668.103
    Safari: 18.0.1
  npmPackages:
    vue: ^3.5.12 => 3.5.12

Any additional comments?

⚠️ It does not occur 100% of the time, but it seems to occur each time the server starts. Sometimes, on HMR, it suddenly works perfectly.

edison1105 commented 1 week ago

a workaround see Playground