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

Clicking the lookup icon, it will keep spining #9

Closed
penn201500 opened this issue Jul 26, 2024 · 1 comment
Closed

Clicking the lookup icon, it will keep spining #9

penn201500 opened this issue Jul 26, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@penn201500
Copy link
Contributor

penn201500 commented Jul 26, 2024

``image

steps:

  1. Open http://127.0.0.1:3000, then input f.com and click the lookup icon with the mouse. I got http://127.0.0.1:3000/_next/data/development/f.com.json?query=f.com with a response of 200 OK; everything works as expected.
    2. After step 1, I click the lookup icon again and still get http://127.0.0.1:3000/_next/data/development/f.com.json?query=f.com with a response of 200 OK, but the spinning icon continues to spin.
    3. Refresh the page; the icon will change from spinning to the original icon again, which is okay.
    4. Press the enter key, get http://127.0.0.1:3000/_next/static/development/_devMiddlewareManifest.json with a response of 200 OK, and the lookup icon is not spinning; it’s working as expected.

I've tried to update the state management, but failed:

const goStage = async (target: string) => {
  setLoading(true);
  try {
    await router.push(toSearchURI(target));
  } catch (error) {
    console.error('Error during navigation:', error);
  } finally {
    setLoading(false);
  }
};

useEffect(() => {
  const handleRouteChange = () => {
    setLoading(false);
  };

  router.events.on('routeChangeComplete', handleRouteChange);
  return () => {
    router.events.off('routeChangeComplete', handleRouteChange);
  };
}, [router.events]);

<Input
  className={`w-full text-center`}
  placeholder={`domain name (e.g. google.com)`}
  value={domain}
  onChange={(e) => setDomain(e.target.value)}
  onKeyDown={(e) => {
    if (isEnter(e)) {
      goStage(domain);
    }
  }}
/>
<Button
  size={`icon`}
  variant={`outline`}
  className={`absolute right-0 rounded-l-none`}
  onClick={() => goStage(domain)}
>
  {loading ? (
    <Loader2 className={`w-4 h-4 animate-spin`} />
  ) : (
    <Send className={`w-4 h-4`} />
  )}
</Button>
@zmh-program zmh-program added the bug Something isn't working label Jul 26, 2024
@zmh-program
Copy link
Owner

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants