Aborting Procedure Calls
By default, tRPC does not cancel requests on unmount. If you want to opt into this behavior, you can provide abortOnUnmount
in your configuration callback.
Globally
client.tsts
// @filename: utils.tsimport {createTRPCNext } from '@trpc/next';export consttrpc =createTRPCNext <AppRouter >({config () {return {// ...abortOnUnmount : true,};},});
client.tsts
// @filename: utils.tsimport {createTRPCNext } from '@trpc/next';export consttrpc =createTRPCNext <AppRouter >({config () {return {// ...abortOnUnmount : true,};},});
Per-request
You may also override this behavior at the request level.
client.tsts
// @filename: pages/posts/[id].tsximport {trpc } from '~/utils/trpc';constPostViewPage :NextPageWithLayout = () => {constid =useRouter ().query .id as string;constpostQuery =trpc .post .byId .useQuery ({id }, {trpc : {abortOnUnmount : true } });return (...)}
client.tsts
// @filename: pages/posts/[id].tsximport {trpc } from '~/utils/trpc';constPostViewPage :NextPageWithLayout = () => {constid =useRouter ().query .id as string;constpostQuery =trpc .post .byId .useQuery ({id }, {trpc : {abortOnUnmount : true } });return (...)}