@@ -317,7 +317,7 @@ export class IdentifierCache {
317
317
let newId = coerceId ( data . id ) ;
318
318
319
319
const keyOptions = getTypeIndex ( this . _cache . types , identifier . type ) ;
320
- let existingIdentifier = detectMerge ( keyOptions , identifier , newId ) ;
320
+ let existingIdentifier = detectMerge ( keyOptions , identifier , data , newId , this . _cache . lids ) ;
321
321
322
322
if ( existingIdentifier ) {
323
323
identifier = this . _mergeRecordIdentifiers ( keyOptions , identifier , existingIdentifier , data , newId as string ) ;
@@ -356,6 +356,9 @@ export class IdentifierCache {
356
356
357
357
// ensure a secondary cache entry for this id for the identifier we do keep
358
358
keyOptions . id [ newId ] = kept ;
359
+ // ensure a secondary cache entry for this id for the abandoned identifier's type we do keep
360
+ let baseKeyOptions = getTypeIndex ( this . _cache . types , existingIdentifier . type ) ;
361
+ baseKeyOptions . id [ newId ] = kept ;
359
362
360
363
// make sure that the `lid` on the data we are processing matches the lid we kept
361
364
data . lid = kept . lid ;
@@ -509,13 +512,23 @@ function performRecordIdentifierUpdate(
509
512
function detectMerge (
510
513
keyOptions : KeyOptions ,
511
514
identifier : StableRecordIdentifier ,
512
- newId : string | null
515
+ data : ResourceIdentifierObject | ExistingResourceObject ,
516
+ newId : string | null ,
517
+ lids : IdentifierMap
513
518
) : StableRecordIdentifier | false {
514
- const { id } = identifier ;
519
+ const { id, type , lid } = identifier ;
515
520
if ( id !== null && id !== newId && newId !== null ) {
516
521
const existingIdentifier = keyOptions . id [ newId ] ;
517
522
518
523
return existingIdentifier !== undefined ? existingIdentifier : false ;
524
+ } else {
525
+ let newType = normalizeModelName ( data . type ) ;
526
+
527
+ if ( id !== null && id === newId && newType === type && data . lid && data . lid !== lid ) {
528
+ const existingIdentifier = lids [ data . lid ] ;
529
+
530
+ return existingIdentifier !== undefined ? existingIdentifier : false ;
531
+ }
519
532
}
520
533
521
534
return false ;
0 commit comments