Skip to content

Commit 6d61bab

Browse files
committed
fix(material/datepicker): error due to synchronous change detection
The month view had a `detectChanges` call that was happening inside a `blur` event which ended up causing re-entrant change detection and hitting an assertion in the framework. These changes remove it since it doesn't appear to be necessary anymore. Fixes #31959. (cherry picked from commit 3665b43)
1 parent ae5fa72 commit 6d61bab

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

src/material/datepicker/calendar-body.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,9 @@ export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterView
615615
const col = cell.getAttribute('data-mat-col');
616616

617617
if (row && col) {
618-
return this.rows[parseInt(row)][parseInt(col)];
618+
// We need the optional read here, because this can
619+
// fire too late when the user is navigating quickly.
620+
return this.rows[parseInt(row)]?.[parseInt(col)] || null;
619621
}
620622
}
621623

src/material/datepicker/month-view.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,12 +462,6 @@ export class MatMonthView<D> implements AfterContentInit, OnChanges, OnDestroy {
462462
this._previewEnd = this._getCellCompareValue(dragRange.end);
463463
}
464464
}
465-
466-
// Note that here we need to use `detectChanges`, rather than `markForCheck`, because
467-
// the way `_focusActiveCell` is set up at the moment makes it fire at the wrong time
468-
// when navigating one month back using the keyboard which will cause this handler
469-
// to throw a "changed after checked" error when updating the preview state.
470-
this._changeDetectorRef.detectChanges();
471465
}
472466
}
473467

0 commit comments

Comments
 (0)