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

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

wobsoriano
Copy link
Contributor

@wobsoriano wobsoriano commented May 17, 2025

WIP: Svelte support

Draft until useStore is usable with reactive Store instances - see TanStack/store#193

Screenshot 2025-05-17 at 6 47 01 AM

@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: b8444cd

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
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 have to wrap the tests here in a $effect.root since useLiveQuery has usage of $effect. More info here - https://svelte.dev/docs/svelte/testing#Unit-and-integration-testing-using-Vitest

})

// Wait for the transaction to be committed
await tx.isPersisted.promise
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since $effect.root can't have an async callback, we have to move this promise out of it and create different $effect.roots

Comment on lines 36 to 37
const state = () => useStore(compiledQuery.results.derivedState).current
const data = () => useStore(compiledQuery.results.derivedArray).current
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally tried to use a $derived function here, but useStore for some reason is not reactive. This is still valid usage.

Copy link

@MAST1999 MAST1999 May 17, 2025

Choose a reason for hiding this comment

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

Same problem in Solid, I think if we want it to work useStore needs to receive a function otherwise the signal/rune for compiledQuery is not registered in useStore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I updated it to not use useStore for now. I think as long as the tests pass then we're good 👍🏼

Choose a reason for hiding this comment

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

The tests may pass but the value will not be reactive, which may cause the component not to update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have you seen the updated code? What do you think about it?

So this means all tanstack store packages needs to be updated then?

@wobsoriano wobsoriano marked this pull request as draft May 18, 2025 01:28
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.

3 participants