Skip to content

Conversation

@zhihengGet
Copy link
Contributor

@zhihengGet zhihengGet commented Feb 27, 2024

i ported svelte-4 query to svelte 5

Done: (i have used below myself and they seem to work just fine)

  • createQuery
  • createMutation
  • useQueryClient

TODO:

  • createQueries (i did it but based on solid not sure if it works)
  • unit tests (pending on svelte 5 on how to test runes)
  • isFetching (svelte 4 version should be ok)
  • isMutating (svelte 4 version should be ok)
  • isRestoring (svelte 4 version should be ok)

i already published this svelte 5 draft version under svelte-query-runes package if people want to try it out ! i personally have been using createQuery and createMutation in my own project it work just fine !

to use it , you can checkout my messy sample code in examples/svelte-melt

if anyone want to take this over please feel free to do so ! i personally only need createQuery and createMutation

@zhihengGet
Copy link
Contributor Author

@lachlancollins in case u want to want on this... fyi

there are 3 form of Reactivity approach currently

Pass Function (recommended)

let a = $state(something) createQuery( ( )=> { return { .... } } // this will be reactive for both $state and $derived and other edge cases 

Pass Attribute Function (currently, i added this for enabled+queryKey)

let a= $state() // will work let b=$derived() // enabled is a fn  createQuery({queryKey: [a] , queryFn:()=>{}, enabled:()=>{} } ) 

passing $derived to queryKey does not work i believe, if u change b, query wont update

let a= $state() let b=$derived() // enabled is a fn  createQuery({queryKey:[b] , queryFn:()=>{}, enabled:()=>{} } ) // BAD
let a= $state() // will work let b=$derived(a+1) // wont work if u pass b to queryKey instead of a(u have to pass ()=>b to key), other options require u to pass functions i.e enabled,  // enabled is a fn  createQuery({queryKey: ()=>[b] , queryFn:()=>{}, enabled:()=>{} } ) // good

pass $state to queryKey & enabled is fine too(..need to be a proxy value) inside it !

let a= $state() // will work createQuery({queryKey: [a] , queryFn:()=>{}, enabled:!a // if a.a is a number then enabled won't work  } ) // queryKey can be something that has $state in it 

output of creaetQuery

we can return function or return a proxy runes , i choose the 2nd one since it has better DX , im not sure if theres some edges cases tho

@lachlancollins lachlancollins changed the title feat : svelte 5 feat: svelte 5 adapter Mar 18, 2024
@max-got
Copy link

max-got commented May 2, 2024

One additional thing i encountered, would be nice to fix this small formatting error in Devtools.svelte:

-<div class="tsqd-parent-container" bind:this={ref} /> +<div class="tsqd-parent-container" bind:this={ref} ></div>

Because of breaking: warn on self-closing non-void HTML tags #11114 it spams the console:

10:55:32 AM [vite-plugin-svelte] .../@tanstack+svelte-query-devtools@5.32.0_@tanstack+svelte-query@5.32.0_svelte@5.0.0-next.120/node_modules/@tanstack/svelte-query-devtools/dist/Devtools.svelte:46:0 Self-closing HTML tags for non-void elements are ambiguous — use `<div ...></div>` rather than `<div ... />`

I can open a separate pr for this, but it's not that bad, it's just annoying 😄

@niemyjski
Copy link

@lachlancollins @zhihengGet what is all left to get this working with latest rc? Is the current approach good?

@niemyjski
Copy link

@niemyjski
Copy link

@lachlancollins @zhihengGet what is all left to get this working with latest rc? Is the current approach good? cc @tannerlinsley

@nx-cloud
Copy link

nx-cloud bot commented Jun 20, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 07e64e7. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


🟥 Failed Commands
nx affected --targets=test:sherif,test:knip,test:eslint,test:lib,test:types,test:build,build --parallel=3
✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@lachlancollins lachlancollins changed the title feat(svelte-query): Svelte 5 adapter WIP: Svelte 5 adapter Jul 26, 2024
@lachlancollins lachlancollins marked this pull request as ready for review July 26, 2024 00:32
Copy link
Member

@lachlancollins lachlancollins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhihengGet I'm going to merge this into a svelte-5-adapter branch.

I hope this will allow more people to contribute and get this over the line - to anybody who has been following this PR, please consider contributing!

@lachlancollins lachlancollins merged commit 4e3325e into TanStack:svelte-5-adapter Jul 26, 2024
@lachlancollins
Copy link
Member

I'd encourage anyone interested to subscribe to the following discussion: #7413

lachlancollins pushed a commit that referenced this pull request Jul 27, 2024
lachlancollins pushed a commit that referenced this pull request Jul 27, 2024
lachlancollins pushed a commit that referenced this pull request Jul 28, 2024
lachlancollins pushed a commit that referenced this pull request Jul 29, 2024
niemyjski added a commit to exceptionless/Exceptionless that referenced this pull request Jul 30, 2024
* Updated to svelte5 dep * added link resources * updated client hooks * Commented out legos * removed unused code * added temp tanstack svelte5 adaptor from pr * WIP rework data tables for svelte5 * Updated svelte * Temp impl for svelte persisted store https://twitter.com/puruvjdev/status/1787037268143689894/photo/1 joshnuss/svelte-persisted-store#251 * WIP Runes * More svelte 5 conversion * Updated package json * WIP Svelte 5 work * Upgraded typography components to runes and use new snippets and props * More runes work * More Svelte 5 work * Updated facet filters to runes * Upgraded to @exceptionless/fetchclient * Updated deps * Upgraded to latest fetch client * Updated shad * Upgrade to eslint 9 https://github.com/sveltejs/kit/pull/12268/files * fixed invalid ref * Converted slots * Updated deps * Added some snippets * WIP Dashboard * Updated tailwind * Fixed copy * Fixed slots * Updated deps * Updated data tables and summaries * More conversion * Updated deps * Converted all components to runes * Some dispatch changes * WIP: Dispatch Changes * Updated deps * more dispatch work * Fixed linting errors * Updated svelte * Updated shad * Updated typescript * Updated deps * Fixed fetch client * Fixed svelte errors. * added conditional icon check * Update deps * WIP: Use svelte-query-runes TanStack/query#6981 * WIP - Reworked snippets and some other fixes. * Updated deps * WIP - Svelte 5 work * Updated deps * Updated to latest tanstack table * WIP: Filter runes work. * Fixed more errors. * Updated deps * Use svelte query pkg * Updated svelte and vitest * Fixed svelte query issues, fixed linting issues, fixed eventing. * Fixed web socket events * Updated deps * Fixed some filtering issues * Fixed persisted store * Updated packages * Fixed filter reactivity * Updated deps * Updated deps * fixed svelte query issues * Use runed media query * Update deps * Use runed media query * Fixed svelte issue with state_unsafe_mutation sveltejs/svelte#12571 * Ensure all runes are serialized with toJSON sveltejs/svelte#9639 * Added document visibility store and fixed more upgrades * Updated deps * Updated queries * WIP: Demoting tabs * Updated deps * Updates to tab promotion * Fixed bind warnings * Updated deps * Use new svelte query apis * Updated deps * Fixed stack promotion * Fixed grid issues * Fixed fetch client issues with the login forms * Added custom auth serializer * Force package install due to svelte 5 peer deps * rebuilt lock file * Update Document Visibility helper to match new runed pattern
lachlancollins pushed a commit that referenced this pull request Jul 31, 2024
lachlancollins pushed a commit that referenced this pull request Aug 2, 2024
docs(svelte-5-adapter): force runes mode for all examples (#7800) * docs(examples): force runes mode for all examples * Fix simple example mounting * Fix type feat(svelte-5-adapter): require options to be passed as function (#7804) * fix(svelte-5-adapter): Require options to be passed as function * More fixes * More fixes * Update examples fix(svelte-5-adapter): function for `createMutation` options (#7805) * fix(svelte-5-adapter): require function for createMutation options * Fix type errors refactor(svelte-5-adapter): simplify createBaseQuery (#7808) * refactor: simplify createBaseQuery * Don't take snapshot of queryKey chore(svelte-5-adapter): tidy-up functions (#7809) * chore(svelte-5-adapter): tidy-up functions * Fix types * Update svelte Fix import extensions chore: ignore state_snapshot_uncloneable in tests
background: {$todos.isFetching ? 'green' : 'transparent'};
transition:: {!$todos.isFetching ? 'all .3s ease' : 'none'};
background: {todos.isFetching ? 'green' : 'transparent'};
transition:: {!todos.isFetching ? 'all .3s ease' : 'none'};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this double :: a typo?

lachlancollins pushed a commit that referenced this pull request Aug 9, 2024
docs(svelte-5-adapter): force runes mode for all examples (#7800) * docs(examples): force runes mode for all examples * Fix simple example mounting * Fix type feat(svelte-5-adapter): require options to be passed as function (#7804) * fix(svelte-5-adapter): Require options to be passed as function * More fixes * More fixes * Update examples fix(svelte-5-adapter): function for `createMutation` options (#7805) * fix(svelte-5-adapter): require function for createMutation options * Fix type errors refactor(svelte-5-adapter): simplify createBaseQuery (#7808) * refactor: simplify createBaseQuery * Don't take snapshot of queryKey chore(svelte-5-adapter): tidy-up functions (#7809) * chore(svelte-5-adapter): tidy-up functions * Fix types * Update svelte Fix import extensions chore: ignore state_snapshot_uncloneable in tests
lachlancollins pushed a commit that referenced this pull request Aug 30, 2024
docs(svelte-5-adapter): force runes mode for all examples (#7800) * docs(examples): force runes mode for all examples * Fix simple example mounting * Fix type feat(svelte-5-adapter): require options to be passed as function (#7804) * fix(svelte-5-adapter): Require options to be passed as function * More fixes * More fixes * Update examples fix(svelte-5-adapter): function for `createMutation` options (#7805) * fix(svelte-5-adapter): require function for createMutation options * Fix type errors refactor(svelte-5-adapter): simplify createBaseQuery (#7808) * refactor: simplify createBaseQuery * Don't take snapshot of queryKey chore(svelte-5-adapter): tidy-up functions (#7809) * chore(svelte-5-adapter): tidy-up functions * Fix types * Update svelte Fix import extensions chore: ignore state_snapshot_uncloneable in tests Fix merge
lachlancollins pushed a commit that referenced this pull request Aug 30, 2024
docs(svelte-5-adapter): force runes mode for all examples (#7800) * docs(examples): force runes mode for all examples * Fix simple example mounting * Fix type feat(svelte-5-adapter): require options to be passed as function (#7804) * fix(svelte-5-adapter): Require options to be passed as function * More fixes * More fixes * Update examples fix(svelte-5-adapter): function for `createMutation` options (#7805) * fix(svelte-5-adapter): require function for createMutation options * Fix type errors refactor(svelte-5-adapter): simplify createBaseQuery (#7808) * refactor: simplify createBaseQuery * Don't take snapshot of queryKey chore(svelte-5-adapter): tidy-up functions (#7809) * chore(svelte-5-adapter): tidy-up functions * Fix types * Update svelte Fix import extensions chore: ignore state_snapshot_uncloneable in tests Fix merge
lachlancollins pushed a commit that referenced this pull request Sep 25, 2024
docs(svelte-5-adapter): force runes mode for all examples (#7800) * docs(examples): force runes mode for all examples * Fix simple example mounting * Fix type feat(svelte-5-adapter): require options to be passed as function (#7804) * fix(svelte-5-adapter): Require options to be passed as function * More fixes * More fixes * Update examples fix(svelte-5-adapter): function for `createMutation` options (#7805) * fix(svelte-5-adapter): require function for createMutation options * Fix type errors refactor(svelte-5-adapter): simplify createBaseQuery (#7808) * refactor: simplify createBaseQuery * Don't take snapshot of queryKey chore(svelte-5-adapter): tidy-up functions (#7809) * chore(svelte-5-adapter): tidy-up functions * Fix types * Update svelte Fix import extensions chore: ignore state_snapshot_uncloneable in tests Fix merge
lachlancollins pushed a commit that referenced this pull request Nov 4, 2024
docs(svelte-5-adapter): force runes mode for all examples (#7800) * docs(examples): force runes mode for all examples * Fix simple example mounting * Fix type feat(svelte-5-adapter): require options to be passed as function (#7804) * fix(svelte-5-adapter): Require options to be passed as function * More fixes * More fixes * Update examples fix(svelte-5-adapter): function for `createMutation` options (#7805) * fix(svelte-5-adapter): require function for createMutation options * Fix type errors refactor(svelte-5-adapter): simplify createBaseQuery (#7808) * refactor: simplify createBaseQuery * Don't take snapshot of queryKey chore(svelte-5-adapter): tidy-up functions (#7809) * chore(svelte-5-adapter): tidy-up functions * Fix types * Update svelte Fix import extensions chore: ignore state_snapshot_uncloneable in tests Fix merge
lachlancollins pushed a commit that referenced this pull request Dec 14, 2024
docs(svelte-5-adapter): force runes mode for all examples (#7800) * docs(examples): force runes mode for all examples * Fix simple example mounting * Fix type feat(svelte-5-adapter): require options to be passed as function (#7804) * fix(svelte-5-adapter): Require options to be passed as function * More fixes * More fixes * Update examples fix(svelte-5-adapter): function for `createMutation` options (#7805) * fix(svelte-5-adapter): require function for createMutation options * Fix type errors refactor(svelte-5-adapter): simplify createBaseQuery (#7808) * refactor: simplify createBaseQuery * Don't take snapshot of queryKey chore(svelte-5-adapter): tidy-up functions (#7809) * chore(svelte-5-adapter): tidy-up functions * Fix types * Update svelte Fix import extensions chore: ignore state_snapshot_uncloneable in tests Fix merge
lachlancollins pushed a commit that referenced this pull request Feb 16, 2025
docs(svelte-5-adapter): force runes mode for all examples (#7800) * docs(examples): force runes mode for all examples * Fix simple example mounting * Fix type feat(svelte-5-adapter): require options to be passed as function (#7804) * fix(svelte-5-adapter): Require options to be passed as function * More fixes * More fixes * Update examples fix(svelte-5-adapter): function for `createMutation` options (#7805) * fix(svelte-5-adapter): require function for createMutation options * Fix type errors refactor(svelte-5-adapter): simplify createBaseQuery (#7808) * refactor: simplify createBaseQuery * Don't take snapshot of queryKey chore(svelte-5-adapter): tidy-up functions (#7809) * chore(svelte-5-adapter): tidy-up functions * Fix types * Update svelte Fix import extensions chore: ignore state_snapshot_uncloneable in tests Fix merge
hmnd pushed a commit to hmnd/tanstack-query that referenced this pull request Apr 3, 2025
docs(svelte-5-adapter): force runes mode for all examples (TanStack#7800) * docs(examples): force runes mode for all examples * Fix simple example mounting * Fix type feat(svelte-5-adapter): require options to be passed as function (TanStack#7804) * fix(svelte-5-adapter): Require options to be passed as function * More fixes * More fixes * Update examples fix(svelte-5-adapter): function for `createMutation` options (TanStack#7805) * fix(svelte-5-adapter): require function for createMutation options * Fix type errors refactor(svelte-5-adapter): simplify createBaseQuery (TanStack#7808) * refactor: simplify createBaseQuery * Don't take snapshot of queryKey chore(svelte-5-adapter): tidy-up functions (TanStack#7809) * chore(svelte-5-adapter): tidy-up functions * Fix types * Update svelte Fix import extensions chore: ignore state_snapshot_uncloneable in tests Fix merge
lachlancollins pushed a commit that referenced this pull request Apr 12, 2025
docs(svelte-5-adapter): force runes mode for all examples (#7800) * docs(examples): force runes mode for all examples * Fix simple example mounting * Fix type feat(svelte-5-adapter): require options to be passed as function (#7804) * fix(svelte-5-adapter): Require options to be passed as function * More fixes * More fixes * Update examples fix(svelte-5-adapter): function for `createMutation` options (#7805) * fix(svelte-5-adapter): require function for createMutation options * Fix type errors refactor(svelte-5-adapter): simplify createBaseQuery (#7808) * refactor: simplify createBaseQuery * Don't take snapshot of queryKey chore(svelte-5-adapter): tidy-up functions (#7809) * chore(svelte-5-adapter): tidy-up functions * Fix types * Update svelte Fix import extensions chore: ignore state_snapshot_uncloneable in tests Fix merge
lachlancollins pushed a commit that referenced this pull request Apr 12, 2025
lachlancollins pushed a commit that referenced this pull request Sep 26, 2025
lachlancollins added a commit that referenced this pull request Sep 30, 2025
* WIP: Svelte 5 adapter (#6981) * feat(svelte-query): Improve svelte runes API (#8852) * feat: Draft proposal * chore: Improve reactive containers * ci: apply automated fixes * oops * fix: Update API, add a bunch of tests * merge main * fix: use const * more tests * feat: More tests, back to thunks, fixed svelte-query-persist-client * feat: More tests and examples! * lockfile * fixes * Fix current CI errors * More small fixes/tweaks * Remove test.only * ci: apply automated fixes * Fix pnpm-lock, fix import order * update main docs * feat: More tests * ci: apply automated fixes * add back old tests * Cleanup * Fix persist client * Fix useMutationState --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Lachlan Collins <1667261+lachlancollins@users.noreply.github.com> * Use sleep from query-test-utils * Simplify test reset logic * Fix some merge conflicts * More fixes * A few more fixes * Fix useMutationState * Add changeset * Add migration docs * Replace Set with SvelteSet * Update minimum svelte version * Bump svelte-eslint-parser * Unwrap createQuery test * fix(svelte-query): `state_unsafe_mutation` error with `useIs...` (#9493) * fix(svelte-query): don't wrap observers in derived to avoid state_unsafe_mutation fixes useIsFetching and useIsMutating in svelte 5 adapter * test(svelte-query): wrap (useIs...) tests in QueryClientProvider to test non colocated query * fix(svelte-query): update observers when passed in query client changes * fix(svelte-query): simplify creatMutation sub/unsub * Refactor result handling in createMutation.svelte.ts Replace derived state with direct state and add watchChanges for result updates. --------- Co-authored-by: Lachlan Collins <1667261+lachlancollins@users.noreply.github.com> * chore(svelte-query): fix eslint config (#9699) * chore(svelte-query): fix eslint config * Use @typescript-eslint/parser directly * ci: apply automated fixes * Fix sherif * Update docs and changeset * Update keywords --------- Co-authored-by: Zhiheng Zhang <55773069+zhihengGet@users.noreply.github.com> Co-authored-by: Elliott Johnson <sejohnson@torchcloudconsulting.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: David <david@hmnd.io>
Hellol77 pushed a commit to Hellol77/query that referenced this pull request Oct 14, 2025
* WIP: Svelte 5 adapter (TanStack#6981) * feat(svelte-query): Improve svelte runes API (TanStack#8852) * feat: Draft proposal * chore: Improve reactive containers * ci: apply automated fixes * oops * fix: Update API, add a bunch of tests * merge main * fix: use const * more tests * feat: More tests, back to thunks, fixed svelte-query-persist-client * feat: More tests and examples! * lockfile * fixes * Fix current CI errors * More small fixes/tweaks * Remove test.only * ci: apply automated fixes * Fix pnpm-lock, fix import order * update main docs * feat: More tests * ci: apply automated fixes * add back old tests * Cleanup * Fix persist client * Fix useMutationState --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Lachlan Collins <1667261+lachlancollins@users.noreply.github.com> * Use sleep from query-test-utils * Simplify test reset logic * Fix some merge conflicts * More fixes * A few more fixes * Fix useMutationState * Add changeset * Add migration docs * Replace Set with SvelteSet * Update minimum svelte version * Bump svelte-eslint-parser * Unwrap createQuery test * fix(svelte-query): `state_unsafe_mutation` error with `useIs...` (TanStack#9493) * fix(svelte-query): don't wrap observers in derived to avoid state_unsafe_mutation fixes useIsFetching and useIsMutating in svelte 5 adapter * test(svelte-query): wrap (useIs...) tests in QueryClientProvider to test non colocated query * fix(svelte-query): update observers when passed in query client changes * fix(svelte-query): simplify creatMutation sub/unsub * Refactor result handling in createMutation.svelte.ts Replace derived state with direct state and add watchChanges for result updates. --------- Co-authored-by: Lachlan Collins <1667261+lachlancollins@users.noreply.github.com> * chore(svelte-query): fix eslint config (TanStack#9699) * chore(svelte-query): fix eslint config * Use @typescript-eslint/parser directly * ci: apply automated fixes * Fix sherif * Update docs and changeset * Update keywords --------- Co-authored-by: Zhiheng Zhang <55773069+zhihengGet@users.noreply.github.com> Co-authored-by: Elliott Johnson <sejohnson@torchcloudconsulting.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: David <david@hmnd.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment