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

Shallow unwrapping creates a feature parity problem with Vue3 #536

Closed
Aaron-Pool opened this issue Sep 22, 2020 · 4 comments
Closed

Shallow unwrapping creates a feature parity problem with Vue3 #536

Aaron-Pool opened this issue Sep 22, 2020 · 4 comments

Comments

@Aaron-Pool
Copy link

Aaron-Pool commented Sep 22, 2020

Release beta.7 integrated the breaking change introduced by vue 3 release here. Unfortunately, this creates an issue in using the composition-api in vue 2.

Evan has 2 suggested fixes in the release notes for people using a plain object with refs:

  1. Wrap the whole thing in reactive, which results in identical behavior as before. However, this doesn't work in the vue 2 api, as reactive mutates the underlying object, meaning those refs are unwrapped everywhere that they were being used or injected, and not just unwrapped in the newly assigned variable,

  2. Just destructure the refs and return them specifically. Evan mentions that the only reason most people bundle refs together in a parent object is because of the verbosity of the return statement otherwise, which can me mitigated quite well by the new <script setup> RFC. This is a fair point, however, the <script setup> functionality doesn't exist in Vue 2, so that is, once again, not an option for Vue2 users.

I'm honestly not sure what the answer here is, but that breaking change kind of put the users of this api in a bit of a maintainability bind. Any advice from the maintainers here would be greatly appreciated @pikax @antfu

@pikax
Copy link
Member

pikax commented Sep 22, 2020

  • Wrap the whole thing in reactive, which results in identical behavior as before. However, this doesn't work in the vue 2 api, as reactive mutates the underlying object, meaning those refs are unwrapped everywhere that they were being used or injected, and not just unwrapped in the newly assigned variable

With the vue2 limitations it makes it really difficult, unfortunately I don't have a good solution, it would be possible to create an copy of the object and unwarp the values (similar to reactive, but without original object mutation), but that would be an api which wouldn't exist in vue3 and it would also possibly add a few more issues.

@Aaron-Pool
Copy link
Author

@pikax Has anyone considered backporting the <script setup> option to the vue 2 compiler? I've looked into doing the webpack loader to do the transform with jscodeshift, which seems like it would be pretty trivial, but the typing seems like it would be pretty challenging to get to work properly, at least in an even remotely ergonomic fashion.

@pikax
Copy link
Member

pikax commented Sep 22, 2020

That SFC is still in RFC vuejs/rfcs#182

I wouldn't expect it to be ported until is merged

@antfu
Copy link
Member

antfu commented Oct 1, 2020

This is not a part of this plugin, should be handled by vue-compiler. You can continue the discussion in the corresponding RFC or the vuejs/vue repo. Closing for now. Thanks.

@antfu antfu closed this as completed Oct 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants