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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[馃悶] Tasks that track the url run again after cleaning up and the component has already been destroyed #4432

Closed
DustinJSilk opened this issue Jun 7, 2023 · 1 comment 路 Fixed by #4459
Assignees
Labels
P4: urgent If Bug - it makes Qwik unstable and affects the majority of users STATUS-1: needs triage New issue which needs to be triaged TYPE: bug Something isn't working

Comments

@DustinJSilk
Copy link
Contributor

Which component is affected?

Qwik Runtime

Describe the bug

When navigating away from the URL, the task cleanup is called, but then the task is run again even though the component is destroyed.
This causes a few unexpected issues to occur.

See the below example, you will notice in the console the logs will show:

Running task for path:  /
Cleaning up task for path /child/
Running task for path:  /child/

When it should show:

Running task for path:  /
Cleaning up task for path /
import { component$, useComputed$, useVisibleTask$ } from "@builder.io/qwik";
import { Link, useLocation } from "@builder.io/qwik-city";

export default component$(() => {
  const { url } = useLocation();

  const pathname = useComputed$(() => url.pathname);

  useVisibleTask$(({ track, cleanup }) => {
    track(() => pathname.value);

    // This should only run on page load for path '/'
    console.log("Running task for path: ", pathname.value);

    // This should only run when leaving the page
    cleanup(() => console.log("Cleaning up task for path", pathname.value));
  });

  return (
    <>
      <Link href="/child/">Click me</Link>
    </>
  );
});

Reproduction

https://github.com/DustinJSilk/qwik-issue-nav-signals

Steps to reproduce

Run the app
Click on the link
See the issue in the console

System Info

N/A

Additional Information

No response

@DustinJSilk DustinJSilk added TYPE: bug Something isn't working STATUS-1: needs triage New issue which needs to be triaged labels Jun 7, 2023
@DustinJSilk DustinJSilk changed the title [馃悶] Tasks that track the url run after cleaning up and the component is destroyed [馃悶] Tasks that track the url run again after cleaning up and the component has already been destroyed Jun 7, 2023
@manucorporat
Copy link
Contributor

Makes sense! I will look into it! great explanation of the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4: urgent If Bug - it makes Qwik unstable and affects the majority of users STATUS-1: needs triage New issue which needs to be triaged TYPE: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants