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

useTemplateRef Fails to Populate Ref Array When Slot Content Is Rendered in v-for #12489

Open
jhillacre opened this issue Nov 29, 2024 · 2 comments
Labels
need documentation Not necessarily a bug, but proper documentation is needed

Comments

@jhillacre
Copy link

jhillacre commented Nov 29, 2024

Vue version

3.5.12, 5a5406d

Link to minimal reproduction

https://play.vuejs.org/#...

Steps to reproduce

  1. Click "Add Item" in either the "Old Syntax" or "New Syntax" sections.
  2. Observe:
    • New Syntax: Ref array remains null or only references the last item.
    • Old Syntax: Focus and scroll behavior work correctly.

What is expected?

useTemplateRef populates myNewItemRefs with an array of referenced elements after they are rendered.

What is actually happening?

useTemplateRef populates myNewItemRefs with the last rendered instance of the referenced element.

System Info

My local vue is running in a WSL instance:

  System:
    OS: Linux 5.15 Fedora Linux 39 (Container Image)
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
    Memory: 22.53 GB / 25.44 GB
    Container: Yes
    Shell: 5.2.26 - /bin/bash
  Binaries:
    Node: 20.18.1 - ~/.nvm/versions/node/v20.18.1/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.18.1/bin/yarn
    npm: 10.9.0 - ~/.nvm/versions/node/v20.18.1/bin/npm
    pnpm: 9.14.4 - ~/.nvm/versions/node/v20.18.1/bin/pnpm
  npmPackages:
    vue: ^3.3.9 => 3.5.12

Any additional comments?

The documentation specifies that useTemplateRef should support v-for, with no mention of exceptions for slots. If this behavior is intentional, the documentation should explicitly state it. Otherwise, this represents an inconsistency with prior behavior and expectations.

@edison1105 edison1105 added the need documentation Not necessarily a bug, but proper documentation is needed label Dec 1, 2024
@edison1105
Copy link
Member

When using ref inside slots, the compiler cannot determine if it is inside a v-for at compile time.
I don't think this is a bug.

@jhillacre
Copy link
Author

When using ref inside slots, the compiler cannot determine if it is inside a v-for at compile time. I don't think this is a bug.

Thanks for the response. I understand how this limitation might fall outside the scope of the useTemplateRefs. Regarding the 'needs documentation' tag, I think this issue can be resolved by outlining the limitation and clarifying that the pre-3.5 syntax is required in such cases. This would help future readers understand the behaviour more clearly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need documentation Not necessarily a bug, but proper documentation is needed
Projects
None yet
Development

No branches or pull requests

2 participants