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

qwik-city: add events to be able to react to the client side navigation #2202

Closed
jwickers opened this issue Nov 20, 2022 · 2 comments
Closed
Labels
STATUS-1: needs triage New issue which needs to be triaged TYPE: enhancement New feature or request
Milestone

Comments

@jwickers
Copy link
Contributor

Is your feature request related to a problem?

It would be nice to be able to react to the client-side navigation as currently, the page does not give any indication of loading which can lead to a bad user experience when trying to load a slow page, or on a slow network.

This should react when using the Link component or the useNavigate hook.

Describe the solution you'd like

Simple events could be dispatched on navigation start and end.

This could then be used in the App layout, where navigation loader could be a top progress bar to indicate something is loading:

  useClientEffect$(() => {
    console.log("adding document event listeners ...");
    const onNavStart = (e:Event) => {
      console.log("qnavigatestart event", e);
      document.getElementById("navigationLoader")?.classList.add("navigating");
    }
    const onNavEnd = (e:Event) => {
      console.log("qnavigateend event", e);
      document
        .getElementById("navigationLoader")
        ?.classList.remove("navigating");
    }
    document.addEventListener("qnavigatestart", onNavStart);
    document.addEventListener("qnavigateend", onNavEnd);
    return () => {
      console.log("removing document event listeners ...");
      document.removeEventListener("qnavigatestart", onNavStart);
      document.removeEventListener("qnavigateend", onNavEnd);
    }
  });

Describe alternatives you've considered

Using a store or signal to store if the navigation is on-going, but AFAICT this did not work well due to render buffering.
Raw events would also be easier to integrate with other libraries.

Additional context

No response

@jwickers jwickers added TYPE: enhancement New feature or request STATUS-1: needs triage New issue which needs to be triaged labels Nov 20, 2022
jwickers added a commit to jwickers/qwik that referenced this issue Nov 20, 2022
Signed-off-by: Jeremy Wickersheimer <jwickers@gmail.com>
@manucorporat manucorporat added this to the 1.0-rc0 milestone Nov 28, 2022
@manucorporat
Copy link
Contributor

Should be possible now to track useLocation() isNavigating, to know when it's actively navigating!

@jwickers
Copy link
Contributor Author

Yes, I saw this was added when I looked at the code source today after the update.
This could work for some use cases, will have to test it.

Not sure if there is a good way to capture start / end for UI updates and potentially prevent navigation just using this.

Currently, there is another issue with the URL not being updated when using navigate though.

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: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants