Skip to content

Commit e9d95a7

Browse files
committed
Update localStoreReleaseTarget so it is a no-op for a non-existent target
1 parent 56fbe52 commit e9d95a7

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

packages/firestore/src/local/local_store_impl.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import { fromVersion, JsonProtoSerializer } from '../remote/serializer';
6262
import { diffArrays } from '../util/array';
6363
import { debugAssert, debugCast, hardAssert } from '../util/assert';
6464
import { ByteString } from '../util/byte_string';
65-
import { logDebug } from '../util/log';
65+
import { logDebug, logWarn } from '../util/log';
6666
import { primitiveComparator } from '../util/misc';
6767
import { ObjectMap } from '../util/obj_map';
6868
import { SortedMap } from '../util/sorted_map';
@@ -1029,22 +1029,22 @@ export async function localStoreReleaseTarget(
10291029
): Promise<void> {
10301030
const localStoreImpl = debugCast(localStore, LocalStoreImpl);
10311031
const targetData = localStoreImpl.targetDataByTarget.get(targetId);
1032-
debugAssert(
1033-
targetData !== null,
1034-
`Tried to release nonexistent target: ${targetId}`
1035-
);
1032+
1033+
if (targetData === null) {
1034+
logWarn(`Tried to release nonexistent target: ${targetId}`);
1035+
}
10361036

10371037
const mode = keepPersistedTargetData ? 'readwrite' : 'readwrite-primary';
10381038

10391039
try {
1040-
if (!keepPersistedTargetData) {
1040+
if (!keepPersistedTargetData && targetData) {
10411041
await localStoreImpl.persistence.runTransaction(
10421042
'Release target',
10431043
mode,
10441044
txn => {
10451045
return localStoreImpl.persistence.referenceDelegate.removeTarget(
10461046
txn,
1047-
targetData!
1047+
targetData
10481048
);
10491049
}
10501050
);
@@ -1067,7 +1067,10 @@ export async function localStoreReleaseTarget(
10671067

10681068
localStoreImpl.targetDataByTarget =
10691069
localStoreImpl.targetDataByTarget.remove(targetId);
1070-
localStoreImpl.targetIdByTarget.delete(targetData!.target);
1070+
1071+
if (targetData) {
1072+
localStoreImpl.targetIdByTarget.delete(targetData!.target);
1073+
}
10711074
}
10721075

10731076
/**

0 commit comments

Comments
 (0)