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

bug: Infinite loop when using useQuery or useSuspenseQuery #1875

Open
ayoubphy opened this issue May 8, 2024 · 1 comment
Open

bug: Infinite loop when using useQuery or useSuspenseQuery #1875

ayoubphy opened this issue May 8, 2024 · 1 comment

Comments

@ayoubphy
Copy link

ayoubphy commented May 8, 2024

Provide environment information

System:
OS: Windows 11 10.0.22000
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Memory: 7.71 GB / 15.89 GB
Binaries:
Node: 20.10.0 - C:\Program Files\nodejs\node.EXE
npm: 10.5.1 - C:\Program Files\nodejs\npm.CMD
pnpm: 8.14.0 - ~\AppData\Roaming\npm\pnpm.CMD
bun: 1.1.3 - ~.bun\bin\bun.EXE

Describe the bug

useQuery keeps infinitely refetching. There was a previous bug report #1771 and a fix was merged in #1772 but it doesn't seem to have fixed the issue.

Reproduction repo

N/A

To reproduce

call trpc.route.procedure.useQuery() or trpc.route.procedure.useSuspenseQuery() inside a page.tsx

Additional information

No response

@ayoubphy ayoubphy changed the title bug: Infinite loop when using useQuery or useSuspenseSuery bug: Infinite loop when using useQuery or useSuspenseQuery May 8, 2024
@saulflores95
Copy link

@ayoubphy I am having a very similar issue

So here is my example

import { api } from "~/trpc/react";
import * as React from "react";

const Reciepts = () => {
  const [startDate, setStartDate] = useState <Date> new Date();

  const {
    data: receipts,
    refetch,
    isLoading,
  } = api.recipiets.getAllByRange.useQuery({
    startDate: startDate,
  });

  return (
    <>
      <Calendar
        mode="single"
        selected={startDate}
        onSelect={(date) => {
          if (date) {
            setStartDate(date);
          }
        }}
      />
    </>
  );
};

export default Receipts

In this example the moment the user changes the date this causes an infinte looop causing the browser to crash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants