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

[🐞] useComputed$ needs to do an equals check #4918

Closed
FlatMapIO opened this issue Aug 9, 2023 · 5 comments · Fixed by #6996
Closed

[🐞] useComputed$ needs to do an equals check #4918

FlatMapIO opened this issue Aug 9, 2023 · 5 comments · Fixed by #6996

Comments

@FlatMapIO
Copy link
Contributor

Which component is affected?

Qwik Runtime

Describe the bug

Currently, computed does not do an equals check, so even if the result is always true, it will still trigger the task to rerun. This is clearly not the expected behavior. I hope useComputed can add an equals option and set it to Object.is, otherwise it seems pointless for it to exist.

Reproduction

https://stackblitz.com/edit/qwik-starter-2t6x22?file=src%2Froutes%2Findex.tsx

Steps to reproduce

export default component$(() => {
  const countRef = useSignal(0);
  const isGreetOneRef = useComputed$(() => {
    return countRef.value > 1;
  });
  useTask$(({ track }) => {
    track(isGreetOneRef);
    console.log(" run task ");
  });
  return (
    <div>
      <button onClick$={() => (countRef.value = countRef.value + 1)}>
        incr
      </button>
    </div>
  );
});

System Info

NONE

Additional Information

No response

@FlatMapIO FlatMapIO added TYPE: bug Something isn't working STATUS-1: needs triage New issue which needs to be triaged labels Aug 9, 2023
@stackblitz
Copy link

stackblitz bot commented Aug 9, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@shairez shairez added WAITING FOR: team Waiting for one of the core team members to review and reply and removed STATUS-1: needs triage New issue which needs to be triaged labels Aug 15, 2023
@shairez
Copy link
Contributor

shairez commented Aug 15, 2023

Thanks for the report @FlatMapIO !

Reviewed it, seems like it's worth investigating further

@gioboa
Copy link
Member

gioboa commented Jun 17, 2024

Same behavior with v1.5.7.
@Varixo is it fixed in v2? can you check it please? Thanks

@Varixo
Copy link
Member

Varixo commented Jul 1, 2024

Same behavior with v1.5.7. @Varixo is it fixed in v2? can you check it please? Thanks

We should check this after v2 signals implementation

@Varixo
Copy link
Member

Varixo commented Oct 27, 2024

Thank you for the clear reproduction! This should be fixed in v2 release, so I am going to close that issue

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

Successfully merging a pull request may close this issue.

4 participants