Make sure all the loader use the abort signal

This makes sure that the loader stops loading when navigating away
This commit is contained in:
Quentin Gliech committed 2024-02-17 09:48:53 +01:00
1 parent f10a1c7830
commit 0d4b941b43
7 files changed
+54 -20

No files matched your search

+6 -2
View File
@@ -39,8 +39,12 @@ const QUERY = graphql(/* GraphQL */ `
`);
export const Route = createFileRoute("/_account/")({
async loader({ context }) {
const result = await context.client.query(QUERY, {});
async loader({ context, abortController: { signal } }) {
const result = await context.client.query(
QUERY,
{},
{ fetchOptions: { signal } },
);
if (result.error) throw result.error;
if (result.data?.viewer.__typename !== "User") throw notFound();
},
@@ -24,8 +24,12 @@ import OAuth2SessionDetail from "../components/SessionDetail/OAuth2SessionDetail
import { graphql } from "../gql";
export const Route = createFileRoute("/_account/sessions/$id")({
async loader({ context, params }) {
const result = await context.client.query(QUERY, { id: params.id });
async loader({ context, params, abortController: { signal } }) {
const result = await context.client.query(
QUERY,
{ id: params.id },
{ fetchOptions: { signal } },
);
if (result.error) throw result.error;
if (!result.data?.node) throw notFound();
},
@@ -32,8 +32,12 @@ const QUERY = graphql(/* GraphQL */ `
`);
export const Route = createFileRoute("/_account/sessions/")({
async loader({ context }) {
const result = await context.client.query(QUERY, {});
async loader({ context, abortController: { signal } }) {
const result = await context.client.query(
QUERY,
{},
{ fetchOptions: { signal } },
);
if (result.error) throw result.error;
if (result.data?.viewer?.__typename !== "User") throw notFound();
},
+6 -2
View File
@@ -31,8 +31,12 @@ const QUERY = graphql(/* GraphQL */ `
`);
export const Route = createFileRoute("/_account")({
loader: async ({ context }) => {
const result = await context.client.query(QUERY, {});
loader: async ({ context, abortController: { signal } }) => {
const result = await context.client.query(
QUERY,
{},
{ fetchOptions: { signal } },
);
if (result.error) throw result.error;
if (result.data?.viewer.__typename !== "User") throw notFound();
},
+6 -2
View File
@@ -27,8 +27,12 @@ const QUERY = graphql(/* GraphQL */ `
`);
export const Route = createFileRoute("/clients/$id")({
loader: async ({ context, params }) => {
const result = await context.client.query(QUERY, { id: params.id });
loader: async ({ context, params, abortController: { signal } }) => {
const result = await context.client.query(
QUERY,
{ id: params.id },
{ fetchOptions: { signal } },
);
if (result.error) throw result.error;
if (!result.data?.oauth2Client) throw notFound();
},
+16 -6
View File
@@ -42,15 +42,25 @@ const QUERY = graphql(/* GraphQL */ `
`);
export const Route = createFileRoute("/devices/$id")({
async loader({ context, params }) {
const viewer = await context.client.query(CURRENT_VIEWER_QUERY, {});
async loader({ context, params, abortController: { signal } }) {
const viewer = await context.client.query(
CURRENT_VIEWER_QUERY,
{},
{
fetchOptions: { signal },
},
);
if (viewer.error) throw viewer.error;
if (viewer.data?.viewer.__typename !== "User") throw notFound();
const result = await context.client.query(QUERY, {
deviceId: params.id,
userId: viewer.data.viewer.id,
});
const result = await context.client.query(
QUERY,
{
deviceId: params.id,
userId: viewer.data.viewer.id,
},
{ fetchOptions: { signal } },
);
if (result.error) throw result.error;
const session = result.data?.session;
if (!session) throw notFound();
+8 -4
View File
@@ -27,10 +27,14 @@ const QUERY = graphql(/* GraphQL */ `
`);
export const Route = createFileRoute("/emails/$id/verify")({
async loader({ context, params }) {
const result = await context.client.query(QUERY, {
id: params.id,
});
async loader({ context, params, abortController: { signal } }) {
const result = await context.client.query(
QUERY,
{
id: params.id,
},
{ fetchOptions: { signal } },
);
if (result.error) throw result.error;
if (!result.data?.userEmail) throw notFound();
},