Skip to content

feat: add Svelte support #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Jul 23, 2025
Merged

Conversation

wobsoriano
Copy link
Contributor

@wobsoriano wobsoriano commented May 17, 2025

Adds Svelte support!

Screenshot 2025-07-21 at 5 29 35 PM

@wobsoriano wobsoriano force-pushed the rob/svelte-support branch from a32fc79 to 558af77 Compare May 17, 2025 13:32
Copy link

changeset-bot bot commented May 17, 2025

🦋 Changeset detected

Latest commit: 1700b2d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tanstack/svelte-db Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@wobsoriano wobsoriano marked this pull request as ready for review May 17, 2025 13:54
@wobsoriano wobsoriano marked this pull request as draft May 18, 2025 01:28
@KyleAMathews KyleAMathews moved this to In Progress in 0.1.0 release Jun 2, 2025
@KyleAMathews KyleAMathews removed the status in 0.1.0 release Jul 2, 2025
@KyleAMathews
Copy link
Collaborator

FYI — we've removed the tanstack/store to do a direct integration w/ the frameworks (more control means more speed). The vue code is a good example of how to directly integrate with framework reactive primitives. Would love to get a Svelte package out! https://github.com/TanStack/db/blob/main/packages/vue-db/src/useLiveQuery.ts

@wobsoriano
Copy link
Contributor Author

FYI — we've removed the tanstack/store to do a direct integration w/ the frameworks (more control means more speed). The vue code is a good example of how to directly integrate with framework reactive primitives. Would love to get a Svelte package out! https://github.com/TanStack/db/blob/main/packages/vue-db/src/useLiveQuery.ts

Awesome. Ill take a look 👀

@teleskop150750
Copy link

The vue code is a good example

Needs some refactoring

@KyleAMathews
Copy link
Collaborator

@teleskop150750 jump in!

@wobsoriano wobsoriano marked this pull request as ready for review July 22, 2025 00:36
@wobsoriano
Copy link
Contributor Author

@KyleAMathews good to review!

Comment on lines +55 to +62
type MaybeGetter<T> = T | (() => T)

function toValue<T>(value: MaybeGetter<T>): T {
if (typeof value === `function`) {
return (value as () => T)()
}
return value
}
Copy link
Contributor Author

@wobsoriano wobsoriano Jul 22, 2025

Choose a reason for hiding this comment

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

In Svelte 5 with runes, the standard is to use getters when passing reactive state

@wobsoriano wobsoriano force-pushed the rob/svelte-support branch from 65f7207 to 352ff73 Compare July 22, 2025 17:12
"description": "Svelte integration for @tanstack/db",
"version": "0.0.0",
"scripts": {
"build": "svelte-package --input ./src --output ./dist --tsconfig ./tsconfig.build.json",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are not using the shared tanstackViteConfig here as we want to use svelte-package to correctly process .svelte.ts and .svelte files.

This is also what the TanStack Svelte 5 adapter does

Copy link
Contributor Author

Choose a reason for hiding this comment

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

prevents svelte-package from generating declarations for @tanstack/db while still allowing proper type resolution during dev and testing

Copy link
Collaborator

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

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

Great stuff! I'm no Svelte expert but Claude & Gemini gave their 👍 😆 & it looks good to me.

@KyleAMathews KyleAMathews merged commit b1e0bf7 into TanStack:main Jul 23, 2025
3 of 4 checks passed
@github-actions github-actions bot mentioned this pull request Jul 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants