-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[🐞] Qwik doesnt check if-statements
before running child useComputed$ or useTask$
#4332
Comments
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
if-statements
before rendering child useComputed$, causing crash
This comment was marked as outdated.
This comment was marked as outdated.
if-statements
before rendering child useComputed$, causing crashif-statements
before running child useComputed$ or useTask$
This comment was marked as outdated.
This comment was marked as outdated.
I keep running into this issue, am I doing something wrong here? |
I wish this bug had more attention! Here's a playground example just to show how bananas this behavior is 🙈 |
@cmbartschat I don't understand, what are you demostrating? You're throwing on purpose there? The "problem" is that the I don't consider this a bug per se, it's more of an unexpected result of splitting your app in tiny parts that update via signals. |
Why wouldn’t it be a bug? Signals are unavoidable and so is splitting an app into smaller parts. So surely it’s a bug if the result is unexpected? Please let me know if I’m missing something fundamental here :) |
Hmm. So a solution would be that the optimizer keeps track of statements that cause a signal to be forwarded, converting then to a filter function, right? And it should first call the filter function and only then the signal function? I wonder how deep this rabbit hole goes, what statements should be converted etc. |
To be honest, I don’t know what a solution would look like, I don’t know the inner workings of qwik or what the various trade offs would be. Do you know if any other framework has solved or suffers from the same issue? |
I don't know of any other framework that converts values into signals and re-renders asynchronously thanks to that. The workaround is to add a ? after signal.value, which the linter doesn't complain about because it doesn't know that it will become a separate function called separately. For me this feels like a P1 issue, maybe P2 because it's unintuitive. |
Yep so the only real work around is to avoid the conditional completely, it kind of is bananas lol Is there any way we can get this issue escalated? |
Sorry for the cryptic example! What I was trying to show is that based on the contract of the Here's another example to show the sorts of things a real world app might try to do. I would describe the problem simply that type narrowing does not work on signals. No matter what we write in the render logic, at runtime, the signal is not type narrowed, because it gets flushed through before the narrowing logic can run. This can be a source of bugs that Typescript cannot detect. |
Ok your real-world example is convincing. It's easy to see that this could lead to frustrating debug sessions. So indeed I think the proper solution is that the optimizer supports filter functions before updating prop signals. But I don't think that's trivial to add. |
@manucorporat @mhevery is there anything we can do about this issue? |
Yeah, this is a hard one. I need to dig deeper into this to see what a fix could be. The issue is that the order in which we process events is not preserved. |
Does this happen in other situations than when signals are proxied in props by the optimizer? If not, I believe a filter function should work |
I have seen other issues on this topic, but I can't find them now. The issue is that the effects should run in the correct order and then prune its children. I think the code should work as written, but we don't process the effects in the correct order which results in this issue. Happy to have a chat if you want to dig deeper into this. |
I'm getting a similar issue where due to conditional rendering I'm getting two of the same component in the DOM—one hidden and one not hidden. Both components' |
@brandonpittman that's by design, because children and parents render independently. So if you render items in slots, they will always render and update even when the slot is not visible. |
That was the conclusion I came to. I created a If the projected content isn't displayed at render, it'll go into a |
Uhm, yes? Not quite sure what you mean, a playground repro would be nice. |
Looks like this will be fixed in V2 🫨❤️ |
This simple example shows how this bug breaks code that appears to work in Qwik. TypeScript does not show any warnings or errors either. For
This way the computation is not async anymore, but at least it's a safe alternative to circumvent situation like this. |
This bug is still present in v2, likely because the qwikloader doesn't add events to the scheduler yet |
how is this a bug ? according to documentation, props are immutable.
The only way I found to overcome this limitation is to pass the signal directly and run again the condition into the child component. |
Yep, currently you'll need to add the conditions and handle the failures in the child components. Im sure once v2 is out there will be capacity to have this resolved. |
should be fixed by #7088 in v2 |
You are a HERO @Varixo. I’ll start testing the alpha versions with my app |
Which component is affected?
Qwik Runtime
Describe the bug
The following code causes Qwik to crash when the button is clicked. Conditionals aren't checked before child component tasks are run when using Signals.
Reproduction
https://github.com/DustinJSilk/qwik-issue-rendering/blob/main/src/routes/index.tsx
Steps to reproduce
Run the app
Click the button
System Info
Additional Information
No response
The text was updated successfully, but these errors were encountered: