@@ -3470,31 +3470,33 @@ Document.prototype.$__reset = function reset() {
3470
3470
let _this = this ;
3471
3471
3472
3472
// Skip for subdocuments
3473
- const subdocs = this . $parent ( ) === this ? this . $getAllSubdocs ( ) : [ ] ;
3474
- const resetArrays = new Set ( ) ;
3475
- for ( const subdoc of subdocs ) {
3476
- const fullPathWithIndexes = subdoc . $__fullPathWithIndexes ( ) ;
3477
- subdoc . $__reset ( ) ;
3478
- if ( this . isModified ( fullPathWithIndexes ) || isParentInit ( fullPathWithIndexes ) ) {
3479
- if ( subdoc . $isDocumentArrayElement ) {
3480
- resetArrays . add ( subdoc . parentArray ( ) ) ;
3481
- } else {
3482
- const parent = subdoc . $parent ( ) ;
3483
- if ( parent === this ) {
3484
- this . $__ . activePaths . clearPath ( subdoc . $basePath ) ;
3485
- } else if ( parent != null && parent . $isSubdocument ) {
3486
- // If map path underneath subdocument, may end up with a case where
3487
- // map path is modified but parent still needs to be reset. See gh-10295
3488
- parent . $__reset ( ) ;
3473
+ const subdocs = ! this . $isSubdocument ? this . $getAllSubdocs ( ) : null ;
3474
+ if ( subdocs && subdocs . length > 0 ) {
3475
+ const resetArrays = new Set ( ) ;
3476
+ for ( const subdoc of subdocs ) {
3477
+ const fullPathWithIndexes = subdoc . $__fullPathWithIndexes ( ) ;
3478
+ subdoc . $__reset ( ) ;
3479
+ if ( this . isModified ( fullPathWithIndexes ) || isParentInit ( fullPathWithIndexes ) ) {
3480
+ if ( subdoc . $isDocumentArrayElement ) {
3481
+ resetArrays . add ( subdoc . parentArray ( ) ) ;
3482
+ } else {
3483
+ const parent = subdoc . $parent ( ) ;
3484
+ if ( parent === this ) {
3485
+ this . $__ . activePaths . clearPath ( subdoc . $basePath ) ;
3486
+ } else if ( parent != null && parent . $isSubdocument ) {
3487
+ // If map path underneath subdocument, may end up with a case where
3488
+ // map path is modified but parent still needs to be reset. See gh-10295
3489
+ parent . $__reset ( ) ;
3490
+ }
3489
3491
}
3490
3492
}
3491
3493
}
3492
- }
3493
3494
3494
- for ( const array of resetArrays ) {
3495
- this . $__ . activePaths . clearPath ( array . $path ( ) ) ;
3496
- array [ arrayAtomicsBackupSymbol ] = array [ arrayAtomicsSymbol ] ;
3497
- array [ arrayAtomicsSymbol ] = { } ;
3495
+ for ( const array of resetArrays ) {
3496
+ this . $__ . activePaths . clearPath ( array . $path ( ) ) ;
3497
+ array [ arrayAtomicsBackupSymbol ] = array [ arrayAtomicsSymbol ] ;
3498
+ array [ arrayAtomicsSymbol ] = { } ;
3499
+ }
3498
3500
}
3499
3501
3500
3502
function isParentInit ( path ) {
0 commit comments