Skip to content

[WIP]: Add Firebase integration #323

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 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

KyleAMathews
Copy link
Collaborator

No description provided.

@KyleAMathews KyleAMathews self-assigned this Jul 28, 2025
Copy link

changeset-bot bot commented Jul 28, 2025

⚠️ No Changeset found

Latest commit: 8296f8e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@KyleAMathews KyleAMathews marked this pull request as draft July 28, 2025 20:25
@stevecastaneda
Copy link

stevecastaneda commented Jul 30, 2025

@KyleAMathews What are your thoughts about changing this parameter to collectionPath? I think collection name implies the name of the collection when it also accepts a path. eg. sub-collections

@devstojko
Copy link

devstojko commented Aug 5, 2025

Hello there,

I took this in progress code and added locally to my project because I need it for firestore and I notice issue that is described below.

The firebaseCollectionOptions function was causing type inference issues when used with
createCollection from @tanstack/react-db. Specifically, when using the collection in queries with
useLiveQuery, TypeScript was unable to infer the correct types for the collection items, resulting in
RefProxyFor always.

The issue stemmed from a type signature mismatch between firebaseCollectionOptions and what
createCollection expects:

  1. firebaseCollectionOptions was returning: CollectionConfig<TItem, TKey> & { utils:
    FirebaseCollectionUtils }
  2. createCollection expects: CollectionConfig & { utils: ... }

The key difference is that CollectionConfig uses a default key type of string | number, while
CollectionConfig<TItem, TKey> uses a generic TKey. This mismatch prevented TypeScript from properly
inferring the item types when the collection was used in queries.

firebaseCollectionOptions with the pattern used by queryCollectionOptions (which works
correctly). The changes include:

  1. Updated return type:
    // Before
    ): CollectionConfig<TItem, TKey> & { utils: FirebaseCollectionUtils } {

// After
): CollectionConfig<TItem> & { utils: FirebaseCollectionUtils } {
2. Updated sync configuration:
// Before
const sync: SyncConfig<TItem, TKey> = {

// After
const sync: SyncConfig<TItem> = {
3. Updated mutation function signatures:
// Before
onInsert: async (params: InsertMutationFnParams<TItem, TKey>): Promise<Array<TKey>> => {

// After
onInsert: async (params: InsertMutationFnParams<TItem>): Promise<Array<string | number>> => {
4. Updated getKey function:
// Before
const getKey = config.getKey || ((item: TItem) => (item as any).id as TKey)

// After
const getKey = config.getKey || ((item: TItem) => (item as any).id as string | number)

With these changes when I use firebaseCollectionOptions inside useLiveQuery combining with leftJoin from another query-db-collection types are inferred properly .

@KyleAMathews
Copy link
Collaborator Author

@devstojko yeah it's pretty rough atm. I'm about to leave on parental leave so if you want to pick up taking it to production-ready, feel free to take it over!

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