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

$refs in slots disappear when wrapping Teleport #2283

Closed
07akioni opened this issue Sep 30, 2020 · 7 comments
Closed

$refs in slots disappear when wrapping Teleport #2283

07akioni opened this issue Sep 30, 2020 · 7 comments
Labels
🐞 bug Something isn't working

Comments

@07akioni
Copy link
Contributor

07akioni commented Sep 30, 2020

Version

3.0.0

Reproduction link

https://codesandbox.io/s/vue-ref-bug-dhsol?file=/src/App.vue

Steps to reproduce

follow the link
image

What is expected?

$refs.ref2 & $refs.ref3 should be bind when focus the input.

What is actually happening?

they are undefined.

@posva posva changed the title somethings $refs value is incorrect $refs in slots disappear when wrapping Teleport Sep 30, 2020
@posva posva added the 🐞 bug Something isn't working label Sep 30, 2020
@LinusBorg
Copy link
Member

LinusBorg commented Sep 30, 2020

doesn't happen when using actual ref()s for the template refs:

https://codesandbox.io/s/vue-ref-bug-issue-2283-jrdvs

I assume it's caused in part by the slot optimizations - when App.vue re-renders, $refs is cleared:

https://github.com/vuejs/vue-next/blob/5d825f318f1c3467dd530e43b09040d9f8793cce/packages/runtime-core/src/renderer.ts#L1457

and all refs are updated in post-render Effects Queued up during the patch() phase by calling setRef():

https://github.com/vuejs/vue-next/blob/5d825f318f1c3467dd530e43b09040d9f8793cce/packages/runtime-core/src/renderer.ts#L551

But as the slot content sent to <lazy-teleport> doesn't need updating, so there's not vdom patching happening and so these refs are not added back to $refs again.

So the setRefs() method is called only once, for ref1 which is in the App.vue template.

Consequnetly, if we make the slot content depending on inputValue, it will update alongside App.vue and all 3 of the refs will be correctly set again each time.

Not sure this bug is limited to teleport. Also, not surte that the clearing of refs actually makes sense? When a vnode is unmounted, setRef will remove the ref anyways?

@07akioni

This comment has been minimized.

@LinusBorg

This comment has been minimized.

@07akioni

This comment has been minimized.

@LinusBorg

This comment has been minimized.

@07akioni

This comment has been minimized.

@code-elf
Copy link

code-elf commented Oct 2, 2020

I just encountered this too. It seems to happen for every ref on elements inside of a child component's slot.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants