From a162b8c2c23af26b4e432221e5207971e59bddfb Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Fri, 13 Mar 2020 10:17:21 +0100 Subject: [PATCH 1/3] fix: Calling Performance to not require dom --- packages/utils/src/misc.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/utils/src/misc.ts b/packages/utils/src/misc.ts index 0c6e1dc6bbf2..dc4733bd741d 100644 --- a/packages/utils/src/misc.ts +++ b/packages/utils/src/misc.ts @@ -349,7 +349,18 @@ function _htmlElementAsString(el: unknown): string { const INITIAL_TIME = Date.now(); let prevNow = 0; -const performanceFallback: Pick = { +/** + * Cross platform compatible partial performance implementation + */ +interface CrossPlatformPerformance { + /** + * Returns the current timestamp in ms + */ + now(): number; + timeOrigin: number; +} + +const performanceFallback: CrossPlatformPerformance = { now(): number { let now = Date.now() - INITIAL_TIME; if (now < prevNow) { @@ -361,10 +372,12 @@ const performanceFallback: Pick = { timeOrigin: INITIAL_TIME, }; -export const crossPlatformPerformance: Pick = (() => { +export const crossPlatformPerformance: CrossPlatformPerformance = (() => { if (isNodeEnv()) { try { - const perfHooks = dynamicRequire(module, 'perf_hooks') as { performance: Performance }; + // tslint:disable-next-line: no-unsafe-any + const perfHooks = dynamicRequire(module, 'perf_hooks'); + // tslint:disable-next-line: no-unsafe-any return perfHooks.performance; } catch (_) { return performanceFallback; From bca2154ac34c143febbd56e864332fae7e790b38 Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Fri, 13 Mar 2020 10:19:55 +0100 Subject: [PATCH 2/3] meta: Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4872f2bc0b16..2dd69981bc3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott - [apm] fix: Use Performance API for timings when available, including Web Workers (#2492) +- [apm] fix: Remove Performance references (#2495) ## 5.14.1 From acd1d6f27a87779dee05f82724e3abd9d222c272 Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Fri, 13 Mar 2020 10:26:42 +0100 Subject: [PATCH 3/3] ref: Type --- packages/utils/src/misc.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/utils/src/misc.ts b/packages/utils/src/misc.ts index dc4733bd741d..a2541549afab 100644 --- a/packages/utils/src/misc.ts +++ b/packages/utils/src/misc.ts @@ -375,9 +375,7 @@ const performanceFallback: CrossPlatformPerformance = { export const crossPlatformPerformance: CrossPlatformPerformance = (() => { if (isNodeEnv()) { try { - // tslint:disable-next-line: no-unsafe-any - const perfHooks = dynamicRequire(module, 'perf_hooks'); - // tslint:disable-next-line: no-unsafe-any + const perfHooks = dynamicRequire(module, 'perf_hooks') as { performance: CrossPlatformPerformance }; return perfHooks.performance; } catch (_) { return performanceFallback;