Skip to content

Commit 58942db

Browse files
atscottthePunderWoman
authored andcommitted
refactor(core): Update method of grabbing native setTimeout and rAF (#55092)
As mentioned in #54600 (comment) a more effective way of getting the unpatched version of a zone-patched API is to grab it from global[Zone.__symbol__('apiname')]. PR Close #55092
1 parent 104dfd4 commit 58942db

1 file changed

Lines changed: 4 additions & 13 deletions

File tree

packages/core/src/util/callback_scheduler.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,20 @@ import {global} from './global';
3535
* @returns a function to cancel the scheduled callback
3636
*/
3737
export function scheduleCallback(callback: Function): () => void {
38-
// Note: the `getNativeRequestAnimationFrame` is used in the `NgZone` class, but we cannot use the
38+
// Note: the `scheduleCallback` is used in the `NgZone` class, but we cannot use the
3939
// `inject` function. The `NgZone` instance may be created manually, and thus the injection
4040
// context will be unavailable. This might be enough to check whether `requestAnimationFrame` is
4141
// available because otherwise, we'll fall back to `setTimeout`.
4242
const hasRequestAnimationFrame = typeof global['requestAnimationFrame'] === 'function';
4343
let nativeRequestAnimationFrame =
4444
hasRequestAnimationFrame ? global['requestAnimationFrame'] : null;
4545
let nativeSetTimeout = global['setTimeout'];
46-
4746
if (typeof Zone !== 'undefined') {
48-
// Note: zone.js sets original implementations on patched APIs behind the
49-
// `__zone_symbol__OriginalDelegate` key (see `attachOriginToPatched`). Given the following
50-
// example: `window.requestAnimationFrame.__zone_symbol__OriginalDelegate`; this would return an
51-
// unpatched implementation of the `requestAnimationFrame`, which isn't intercepted by the
52-
// Angular zone. We use the unpatched implementation to avoid another change detection when
53-
// coalescing tasks.
54-
const ORIGINAL_DELEGATE_SYMBOL = (Zone as any).__symbol__('OriginalDelegate');
55-
if (nativeRequestAnimationFrame) {
47+
if (hasRequestAnimationFrame) {
5648
nativeRequestAnimationFrame =
57-
(nativeRequestAnimationFrame as any)[ORIGINAL_DELEGATE_SYMBOL] ??
58-
nativeRequestAnimationFrame;
49+
global[Zone.__symbol__('requestAnimationFrame')] ?? nativeRequestAnimationFrame;
5950
}
60-
nativeSetTimeout = (nativeSetTimeout as any)[ORIGINAL_DELEGATE_SYMBOL] ?? nativeSetTimeout;
51+
nativeSetTimeout = global[Zone.__symbol__('setTimeout')] ?? nativeSetTimeout;
6152
}
6253

6354
let executeCallback = true;

0 commit comments

Comments
 (0)