Skip to content
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

Fixed fetching document with duplicate IDs #90

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/hooks/use-swr-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { isDev } from '../helpers/is-dev'
import { withDocumentDatesParsed } from '../helpers/doc-date-parser'
import { deleteDocument } from './static-mutations'


type Options<Doc extends Document = Document> = {
/**
* If `true`, sets up a real-time subscription to the Firestore backend.
Expand Down Expand Up @@ -95,10 +95,8 @@ export const getDocument = async <Doc extends Document = Document>(
})

// update the document in any collections listening to the same document
let collection: string | string[] = path.split(`/${data.id}`)
const collection = path.slice(0, -(`/${data.id}`.length))

collection.pop() // remove last item, which is the /id
collection = collection.join('/') // rejoin the path
if (collection) {
collectionCache.getSWRKeysFromCollectionPath(collection).forEach(key => {
mutate(
Expand Down