@@ -454,6 +454,13 @@ type DocClassification =
454454 | { type : 'unchanged' }
455455 | { type : 'drop' }
456456
457+ export function shouldReplaceExistingWithSkippedDocument (
458+ existing : { storageKey ?: string | null } ,
459+ skipped : Pick < ExternalDocument , 'skippedExistingDisposition' >
460+ ) : boolean {
461+ return existing . storageKey === null || skipped . skippedExistingDisposition === 'replace'
462+ }
463+
457464/**
458465 * Decides what a listed external document becomes during reconciliation.
459466 *
@@ -487,7 +494,7 @@ export function classifyExternalDoc(
487494) : DocClassification {
488495 if ( extDoc . skippedReason ) {
489496 if ( ! existing ) return { type : 'skip' }
490- return existing . storageKey === null || extDoc . skippedExistingDisposition === 'replace'
497+ return shouldReplaceExistingWithSkippedDocument ( existing , extDoc )
491498 ? { type : 'skip' , existingId : existing . id }
492499 : { type : 'unchanged' }
493500 }
@@ -2377,7 +2384,8 @@ export async function executeSync(
23772384 extDoc : mergeHydratedSkippedDocument ( op . extDoc , fullDoc ) ,
23782385 } )
23792386 } else if ( op . type === 'update' ) {
2380- if ( fullDoc . skippedExistingDisposition === 'replace' ) {
2387+ const existing = priorByExternalId . get ( op . extDoc . externalId )
2388+ if ( existing && shouldReplaceExistingWithSkippedDocument ( existing , fullDoc ) ) {
23812389 skipOps . push ( {
23822390 type : 'skip' ,
23832391 existingId : op . existingId ,
0 commit comments