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 are set to null instead of undefined when components are destroyed in vue v2.7.0-alpha.5 #12554

Closed
pdanpdan opened this issue Jun 8, 2022 · 4 comments

Comments

@pdanpdan
Copy link
Contributor

pdanpdan commented Jun 8, 2022

Version

2.7.0-alpha.5

Reproduction link

codepen.io

Steps to reproduce

Press the toggle button to cycle the ref

Working case with v2.6.14: https://codepen.io/pdanpdan/pen/QWQVXmr

Failing case with v2.7.0-alpha.5: https://codepen.io/pdanpdan/pen/JjpaQOP

What is expected?

this.$refs.test to be an element or undefined

What is actually happening?

this.$refs.test is null

@posva
Copy link
Member

posva commented Jun 9, 2022

As a workaround, you can do a loose comparison (pretty common for null): ref == null -> true for undefined and null

@pdanpdan
Copy link
Contributor Author

pdanpdan commented Jun 9, 2022

Yes, I know, but:

  • either the change was intentional and it should be documented as a breaking change (and maybe the initial value should be null too)
  • or it was an undesired side effect of backporting from vue3 and it should be fixed

As this is alpha stage I think it is a good time for such reports.

@tony19
Copy link

tony19 commented Jun 13, 2022

The template ref-removal behavior in 2.7.0-alpha differs from 2.6, but it's consistent with Vue 3 (demo) and with @vue/composition-api in Vue 2.6 (demo).

The behavior was introduced in 4608565:

const value = isRemoval ? null : refValue

Changing that line's null to undefined would restore the original behavior, but would cause inconsistencies with Vue 3. I think it was actually intentional, as the unit tests even explicitly check for null. Perhaps migration docs should be added.

@qiannianchong25
Copy link

I don't think is a problem.When the node or component doesn't exit,the component's $refs should delete related key.so return undefined rather than null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants