Subscribe on changes!

bug when trigger the function in props

avatar
Sep 14th 2023

Vue version

3.3.4

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-qh2ne5?file=src%2FApp.tsx,package.json

Steps to reproduce

add 1 item then add 1 item then add 1 item then add 1 item

click the first delete-button and then click the first delete-button twice , and go on clicking it ,

you can see that the last item can't be deleted

What is expected?

last item can be deleted

What is actually happening?

the last one can't be deleted because the index in the onDelete function callback is not correct

System Info

No response

Any additional comments?

No response

avatar
Sep 14th 2023

The index is cached by the closure, which causes the index to still be the original value after deleting the element, resulting in a deletion error.

avatar
Sep 15th 2023
setup(props) {
    
    return () => {
    // when deconstructing props, move that into the render function. setup itself only runs once.
      const { item, onDelete } = props;
      return (<div>
        <input
          type="checkbox"
   
avatar
Sep 18th 2023

thank you @LinusBorg