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

Store is not available to functional components #1549

Open
joaovitoras opened this issue May 15, 2020 · 6 comments
Open

Store is not available to functional components #1549

joaovitoras opened this issue May 15, 2020 · 6 comments

Comments

@joaovitoras
Copy link

@joaovitoras joaovitoras commented May 15, 2020

Version

1.0.0-beta.29

Reproduction link

https://jsfiddle.net/joaovitoras/37sc6Len/

Steps to reproduce

  • Creates a FunctionalComponent that renders the Balloon component

  • The Balloon component uses the vuex state in template

  • When I mount with VueTestUtils the Main component that contains the Functional Component, store is unavailable and breaks the code

  • When I mount with Vue the Main component works fine https://jsfiddle.net/joaovitoras/hnawzo43/

What is expected?

I hope that somehow the store will be available in the component rendered by the functional component

What is actually happening?

store is not available

@dobromir-hristov
Copy link
Collaborator

@dobromir-hristov dobromir-hristov commented May 15, 2020

Unfortunately I have no solution for you... What environment are you writing your tests in?

@joaovitoras
Copy link
Author

@joaovitoras joaovitoras commented May 15, 2020

Node: v10.19.0
Packages:
vue: "^2.6.11"vue: "^2.6.11"
vuex: "^3.2.0"
jest": "^24.9.0"
@vue/test-utils": "1.0.0-beta.29"

@lmiller1990
Copy link
Member

@lmiller1990 lmiller1990 commented May 17, 2020

maybe related #1507

this.$router/this.$store seems not to work in functional component.

@vhoyer
Copy link

@vhoyer vhoyer commented May 17, 2020

Well, @joaovitoras, have you tried not using the localVue and using the global instead, I think in your example there is no need for it, right?

@lmiller1990
Copy link
Member

@lmiller1990 lmiller1990 commented May 17, 2020

You can try ^ however I would expect the same problem to manifest.

Unrelated, but is common to use a non-functional component inside a functional component? This seems very strange to me - functional (aka stateless) components are normally UI only, and the very "bottom" of the render tree.

It seems strange that they would then contain more complexity via a stateful component.

I could be completely wrong here, since I don't have context - in my apps I never render a stateful component inside a functional component.

This is still definitely a bug in VTU that should be fixed. Based on my explorations a few days ago, I have no idea why this happens or how to fix it at this point in time.

@joaovitoras
Copy link
Author

@joaovitoras joaovitoras commented May 25, 2020

Tks @lmiller1990. I decided by changing how the feature was made instead of trying to use vuex with the functional

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

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.