Svelte 5 Support #7413
-
I'm wondering what is left to support svelte 5 and if the current approach is good. A lot of Svelte 5 apps are blocked so just trying to get a consensus of where community can help. #6981 |
Beta Was this translation helpful? Give feedback.
Replies: 16 comments 96 replies
-
I've been pretty limited for time to look into this. Is anyone else free to take the lead until I get more time? |
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
-
How can I try this?The svelte 5 adapter is currently available on a branch: https://github.com/TanStack/query/tree/svelte-5-adapter Each commit has a package preview - you can install a preview by running What is left to do?Now that svelte 5 is out, it hopefully shouldn't be long before this is released. Please try out the package and report any issues! |
Beta Was this translation helpful? Give feedback.
-
@lachlancollins here is the most minimal version of my repo https://github.com/jakubdonovan/testing-svelte5query
|
Beta Was this translation helpful? Give feedback.
-
To anyone following along, I've introduced a breaking change in #7804 To migrate, you will need to define options as functions, just like solid-query: |
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
-
Can we please get an updated build and or update on merging into main. |
Beta Was this translation helpful? Give feedback.
-
Has anyone ran into an issue with mutateAsync? I'm using superforms with spa mode and when I await it returns the data correctly but immediately checking the mutate variable says it's pending. If I sleep/await a timeout for 1ms and check again it's correct. Think on:input calls form validation, which calls mutateAsync. |
Beta Was this translation helpful? Give feedback.
-
Any timeline to getting the |
Beta Was this translation helpful? Give feedback.
This comment was marked as spam.
This comment was marked as spam.
-
I have tried the svelte 5 branch on my app and so far I have encountered one issue where a mutation like the one below causes a import { createMutation } from "@tanstack/svelte-query";
import type { QueryClient } from "@tanstack/svelte-query";
const updateItem = async (id: string) => {
const response = await fetch(`/api/items/${id}`);
return response.json();
};
const getItem = async (id: string) => {
const response = await fetch(`/api/items/${id}`);
return response.json();
};
export const changeItem = (client: QueryClient) => {
const mutation = createMutation(() => ({
mutationFn: async ({ id }: { id: string }) => {
const updateResponse = await updateItem(id);
// Fetching another query inside mutationFn causes the `state_unsafe_mutation` error
await client.fetchQuery({
queryKey: ["item", id],
queryFn: () => getItem(id)
});
return updateResponse;
},
}));
return mutation;
}; In development the error does not seem to affect the app's functionality and the query is correctly fetched and the UI updates accordingly. Is this a known limitation? |
Beta Was this translation helpful? Give feedback.
-
I opened #8540. I think it concerns us too. |
Beta Was this translation helpful? Give feedback.
-
The https://github.com/TanStack/query/tree/svelte-5-adapter branch seems to be falling behind |
Beta Was this translation helpful? Give feedback.
-
Should it be relying on The proxying that Svelte does also makes it harder for query data manipulation, the values that you get from |
Beta Was this translation helpful? Give feedback.
-
I hope we will get the working adapter soon, rn we have some issues with Svelte 4 version in our Svelte 5 project :c |
Beta Was this translation helpful? Give feedback.
-
I am wondering if an issue I am dealing with is a problem with my code or the package: Let's say I have the following code in the let query = useGetAllProducts();
if (query.isLoading) {
console.log("loading");
}
if (query.isError) {
console.log(query.error);
}
let searchQuery = $state("");
let filteredProducts: Product[] = $state([]);
$effect(() => {
if (query.data) {
filteredProducts = query.data.filter((product) => product.name.includes(searchQuery));
}
}); The code above works fine, when the data is available, it will render everything properly on the screen however if I try to destructure, like below: let { data: products, isLoading, isError, error } = useGetAllProducts();
if (isLoading) {
console.log("loading");
}
if (isError) {
console.log(error);
}
let searchQuery = $state("");
let filteredProducts: Product[] = $state([]);
$effect(() => {
if (products) {
filteredProducts = products.filter((product) => product.name.includes(searchQuery));
}
}); The code stops working. By "stop working" I mean: it fetches the data (as I can see the JSON retrieved from the external API in the console), but it does not render the information on the screen, as if the package is uncapable of identifying that the data is now available. Let me know if you need the full code. Edit note: Here is the implementation of import { ProductSchema } from "$lib/schemas/Products";
import { BASE_URL } from "$lib/utils/consts";
import { createQuery } from "@tanstack/svelte-query";
import { z } from "zod";
const GetAllProductsResponseSchema = z.array(ProductSchema);
export type GetAllProductsResponse = z.infer<typeof GetAllProductsResponseSchema>;
async function getAllProducts() {
const response = await fetch(`${BASE_URL}/products/`, {
headers: {
"Content-Type": "application/json"
});
const body = await response.json();
return GetAllProductsResponseSchema.parse(body.products);
}
export function useGetAllProducts() {
return createQuery(() => ({
queryKey: ["products"],
queryFn: async () => await getAllProducts()
}));
} |
Beta Was this translation helpful? Give feedback.
How can I try this?
The svelte 5 adapter is currently available on a branch: https://github.com/TanStack/query/tree/svelte-5-adapter
Each commit has a package preview - you can install a preview by running
pnpm add https://pkg.pr.new/@tanstack/svelte-query@<LATEST COMMIT HASH>
(e.g. https://pkg.pr.new/@tanstack/svelte-query@ee9346a)What is left to do?
Now that svelte 5 is out, it hopefully shouldn't be long before this is released. Please try out the package and report any issues!