Aborting

By default, Eden-Query does not cancel requests via Svelte Query. If you want to opt into this behaviour, you can provide abortOnUnmount in your configuration.

INFO

@tanstack/svelte-query only supports aborting queries.

TIP

Although this property is named abortOnUnmount, it actually means "forward signal from tanstack-query". tanstack-query's signal facilitates additional functionality such as cancelling requests if there's already a duplicate in-progress. This has been discussed within tRPC here.

Setup

Elysia Server Application

src/server/index.ts
import { Elysia, t } from 'elysia' const postSchema = t.Object({ id: t.String(), message: t.String(), }) type Post = typeof postSchema.static const data: Record<string, Post> = {} const app = new Elysia() .get('/', async () => { return 'Hello, Elysia' }) .get('/posts', async () => { return data }) .get('/posts/:id', async ({ params: { id } }) => { return data[id] }) .post('/posts/:id', async ({ body, params: { id } }) => { data[id] = body return data[id] }, { body: postSchema }) .delete('/posts/:id', async ({ params: { id } }) => { delete data[id] }) export type App = typeof app

Eden-Query Hooks

src/lib/eden.ts
import { createEdenTreatySvelteQuery, type InferTreatyQueryInput, type InferTreatyQueryOutput, } from '@ap0nia/eden-svelte-query' import type { App } from '$server/index' export const eden = createEdenTreatySvelteQuery<App>() export type InferInput = InferTreatyQueryInput<App> export type InferOutput = InferTreatyQueryOutput<App>

Globally

src/lib/eden.ts
import { createEdenTreatySvelteQuery } from '@ap0nia/eden-svelte-query' import type { App } from '$server/index' export const eden = createEdenTreatySvelteQuery<App>({ abortOnUnmount: true, })

Per-request

You may also override this behaviour at the query level.

src/routes/+page.svelte
<script lang="ts" context="module"> </script> <script lang="ts"> import { eden } from '$lib/eden' import type { PageData } from './$types' export let data: PageData const query = eden.posts({ id: data.id }).get.createQuery(undefined, { eden: { abortOnUnmount: true } }) </script>