Skip to content

Commit

Permalink
fix(core): make revisionId required in getDocumentAtRevision
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin committed Dec 9, 2024
1 parent 6aad3bb commit a920056
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ export function getDocumentAtRevision({
}: {
client: SanityClient
documentId: string
revisionId: string | null | undefined
revisionId: string
}): Observable<EventsStoreRevision | null> {
if (!revisionId) {
return of(null)
}
const cacheKey = `${documentId}@${revisionId}`
const dataset = client.config().dataset
if (documentRevisionCache[cacheKey]) {
Expand Down
5 changes: 3 additions & 2 deletions packages/sanity/src/core/store/events/useEventsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export function useEventsStore({
}, [events, rev])

const revision$ = useMemo(
() => getDocumentAtRevision({client, documentId, revisionId: revisionId}),
() =>
revisionId ? getDocumentAtRevision({client, documentId, revisionId: revisionId}) : of(null),
[client, documentId, revisionId],
)
const revision = useObservable(revision$, null)
Expand All @@ -122,7 +123,7 @@ export function useEventsStore({
}, [events, revisionId, since])

const since$ = useMemo(
() => getDocumentAtRevision({client, documentId, revisionId: sinceId}),
() => (sinceId ? getDocumentAtRevision({client, documentId, revisionId: sinceId}) : of(null)),
[sinceId, client, documentId],
)

Expand Down

0 comments on commit a920056

Please sign in to comment.