Skip to content

Commit

Permalink
fix: queuedRetries could overlap if the same key was used in differen…
Browse files Browse the repository at this point in the history
…t observables
  • Loading branch information
jmeistrich committed Nov 4, 2024
1 parent c3e5706 commit 339f7e8
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/sync-plugins/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,18 @@ function computeLastSync(data: any[], fieldUpdatedAt: string | undefined, fieldC
return newLastSync;
}

const queuedRetries = {
create: new Map<string, any>(),
update: new Map<string, any>(),
delete: new Map<string, any>(),
};
function retrySet(
params: SyncedSetParams<any>,
retry: RetryOptions | undefined,
action: 'create' | 'update' | 'delete',
itemKey: string,
itemValue: any,
change: Change,
queuedRetries: {
create: Map<string, any>;
update: Map<string, any>;
delete: Map<string, any>;
},
actionFn: (value: any, params: SyncedSetParams<any>) => Promise<any>,
saveResult: (itemKey: string, itemValue: any, result: any, isCreate: boolean, change: Change) => void,
) {
Expand Down Expand Up @@ -219,6 +219,11 @@ export function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption e

const fieldId = fieldIdProp || 'id';
const pendingCreates = new Set<string>();
const queuedRetries = {
create: new Map<string, any>(),
update: new Map<string, any>(),
delete: new Map<string, any>(),
};

let asType = props.as as TAsOption;

Expand Down Expand Up @@ -578,6 +583,7 @@ export function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption e
itemKey,
createObj,
changesById.get(itemKey)!,
queuedRetries,
createFn!,
saveResult,
).then(() => {
Expand All @@ -599,6 +605,7 @@ export function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption e
itemKey,
changed,
changesById.get(itemKey)!,
queuedRetries,
updateFn!,
saveResult,
);
Expand Down Expand Up @@ -627,6 +634,7 @@ export function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption e
itemKey,
valuePrevious,
changesById.get(itemKey)!,
queuedRetries,
deleteFn!,
saveResult,
);
Expand All @@ -640,6 +648,7 @@ export function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption e
itemKey,
{ [fieldId]: itemKey, [fieldDeleted]: true } as any,
changesById.get(itemKey)!,
queuedRetries,
updateFn!,
saveResult,
);
Expand Down

0 comments on commit 339f7e8

Please sign in to comment.