diff --git a/packages/core/change-detection-scheduler/change-detection-scheduler.ts b/packages/core/change-detection-scheduler/change-detection-scheduler.ts index 5770c84..26db44f 100644 --- a/packages/core/change-detection-scheduler/change-detection-scheduler.ts +++ b/packages/core/change-detection-scheduler/change-detection-scheduler.ts @@ -1,6 +1,7 @@ import { ApplicationRef, ChangeDetectorRef, Component, Injectable, NgZone } from '@angular/core'; const SCHEDULER_PATCHED = new WeakMap(); +const ORIGINAL_MARK_FOR_CHECK = '__markForCheck__'; let tickScheduled = false; export abstract class ChangeDetectionScheduler { @@ -25,22 +26,19 @@ export class ChangeDetectionScheduler_ implements ChangeDetectionScheduler { }) export class ChangeDetectionSchedulerInitializer { constructor(appRef: ApplicationRef, cdRef: ChangeDetectorRef, ngZone: NgZone, scheduler: ChangeDetectionScheduler) { - const markForCheck = cdRef.markForCheck; - - const scheduleTickIfNeeded = () => { - if (!(ngZone instanceof NgZone) && !tickScheduled) { - scheduler.schedule(); - } - }; - while (typeof cdRef === 'object' && !cdRef.hasOwnProperty('markForCheck') && cdRef.constructor.prototype) { cdRef = cdRef.constructor.prototype; } if (!SCHEDULER_PATCHED.has(cdRef) || SCHEDULER_PATCHED.get(cdRef) !== appRef) { + if ((cdRef as any)[ORIGINAL_MARK_FOR_CHECK] == null) { + (cdRef as any)[ORIGINAL_MARK_FOR_CHECK] = cdRef.markForCheck; + } cdRef.markForCheck = function () { - markForCheck.call(this); - scheduleTickIfNeeded(); + (cdRef as any)[ORIGINAL_MARK_FOR_CHECK].call(this); + if (!(ngZone instanceof NgZone) && !tickScheduled) { + scheduler.schedule(); + } }; SCHEDULER_PATCHED.set(cdRef, appRef);