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

Subtle problems with global state #535

Closed
phbender opened this issue Sep 22, 2020 · 6 comments
Closed

Subtle problems with global state #535

phbender opened this issue Sep 22, 2020 · 6 comments

Comments

@phbender
Copy link

phbender commented Sep 22, 2020

When components are imported synchronously, a file using reactive or ref on the module level (outside of functions) may be read before the application is created. This leads to an error on the console:

Error: [vue-composition-api] No vue dependency found.

To work around the problem, the consuming component can be made an asynchronous one (with the Component: () => import('./Component') syntax.

Otherwise, only ref or reactive declared within a function body (which is called after the app has been loaded) seems to work.

In Vue3, I could not reproduce the same.

@pikax
Copy link
Member

pikax commented Sep 22, 2020

Can you provide a repo or code sandbox?

@jacekkarczmarczyk
Copy link
Contributor

Also are you using the latest version? https://github.com/vuejs/composition-api/releases/tag/v1.0.0-beta.14

@zippaaa
Copy link

zippaaa commented Sep 22, 2020

When components are imported synchronously, a file using reactive or ref on the module level (outside of functions) may be read before the application is created. This leads to an error on the console:

You can solve this problem like this
main.js

import Vue from 'vue';
// import VueCompositionAPI from '@vue/composition-api';
// Vue.use(VueCompositionAPI);
import './composition-api'; // <---
...

composition-api.js

import Vue from 'vue';
import VueCompositionAPI from '@vue/composition-api';
Vue.use(VueCompositionAPI);

@phbender
Copy link
Author

@alekseymvt Thanks, this solves it and at the same time adds no complexity to the code that would be redundant with Vue3.

phbender pushed a commit to phbender/composition-api that referenced this issue Sep 23, 2020
phbender pushed a commit to phbender/composition-api that referenced this issue Sep 23, 2020
@phbender
Copy link
Author

phbender commented Sep 23, 2020

I have added the snippet from @alekseymvt to the readme. I think that this is a difference to the behaviour in Vue3 and maybe it saves others from headache, too. See PR above.

@lewebsimple
Copy link

Just came here to say I've had this issue caused by upgrading to vue-demi@0.12
See vueuse/vue-demi#113

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

6 participants