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

[🐞] V2 - Exporting a useStore and a component$ causes the useStore to lose its “this” #7137

Closed
devcaeg opened this issue Dec 7, 2024 · 5 comments
Labels
STATUS-1: needs triage New issue which needs to be triaged TYPE: bug Something isn't working

Comments

@devcaeg
Copy link

devcaeg commented Dec 7, 2024

Which component is affected?

Qwik Runtime

Describe the bug

If a hook returns a useStore and a component$, and the useStore uses function to access “this”, the “this” is undefined.

Reproduction

https://stackblitz.com/edit/github-6f6maw-cm569smw?file=src%2Fhooks%2Ftest.tsx,src%2Froutes%2Findex.tsx

Steps to reproduce

If you click on the “submit” button, you will see an error, since the “this” in the “onSubmit” of the “useStore” is “undefined”.

On the other hand, if in the “useForm”, you remove the export of the “Form” component, the error disappears.

System Info

npmPackages:
    @qwik.dev/core: 2.0.0-alpha.2
    @qwik.dev/router: 2.0.0-alpha.2
    typescript: 5.7.2
    undici: 7.0.0 
    vite: 6.0.1

Additional Information

No response

@devcaeg devcaeg added STATUS-1: needs triage New issue which needs to be triaged TYPE: bug Something isn't working labels Dec 7, 2024
@wmertens
Copy link
Member

wmertens commented Dec 7, 2024

I see you're just calling await onSubmit(), isn't that why this is undefined?

@wmertens
Copy link
Member

wmertens commented Dec 7, 2024

@devcaeg actually, are you looking to have this be the store? You need to do that in this way: #5087 (comment)

@devcaeg
Copy link
Author

devcaeg commented Dec 7, 2024

@wmertens I'm actually basing this on what the documentation says:

https://qwik.dev/docs/components/state/#methods

@devcaeg
Copy link
Author

devcaeg commented Dec 7, 2024

I see you're just calling await onSubmit(), isn't that why this is undefined?

You are right, my mistake haha, I should do “await store.submit()”.

The weird thing is that this bug of mine, I have it for many months running in v1. I mean, although I recognize that it's my fault, anyway in v1 it works and in v2 it doesn't haha.

@wmertens
Copy link
Member

wmertens commented Dec 7, 2024

Ok so I'll close, it seems to be accidently working in V1 but doesn't seem proper.

@wmertens wmertens closed this as completed Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
STATUS-1: needs triage New issue which needs to be triaged TYPE: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants