Skip to content

Commit

Permalink
fix: fix issue with applyMutation not writing back to documentMap
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Oct 31, 2024
1 parent 7d12e87 commit 7051419
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/local/documentMap/applyMutations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {type Mutation, type SanityDocumentBase} from '../../mutations/types'
import {type DocumentMap} from '../types'
import {getMutationDocumentId} from '../utils/getMutationDocumentId'
import {applyDocumentMutation} from './applyDocumentMutation'

Expand All @@ -15,7 +16,7 @@ export interface UpdateResult<T extends SanityDocumentBase> {
*/
export function applyMutations<T extends SanityDocumentBase>(
mutations: Mutation[],
documentMap: {get: (id: string) => T | undefined},
documentMap: DocumentMap<T>,
): UpdateResult<T>[] {
const updatedDocs: Record<
string,
Expand Down Expand Up @@ -48,6 +49,8 @@ export function applyMutations<T extends SanityDocumentBase>(
if (!(documentId in updatedDocs)) {
updatedDocs[documentId] = {before, after: undefined, muts: []}
}
documentMap.set(documentId, res.after)

updatedDocs[documentId]!.after = res.after
}
}
Expand Down

0 comments on commit 7051419

Please sign in to comment.