Fix: Check if global exists before using it
Summary:
Similar to calling global can be troublesome since it doesn't always exist, for instance when using vite.
Pull Request resolved:
'use strict';
const isPerformanceNowAvailable =
- global.performance != null && typeof global.performance.now === 'function';
+ typeof window !== 'undefined' &&
+ typeof window?.performance?.now === 'function';
function currentTimestamp(): number {
if (isPerformanceNowAvailable) {
- return global.performance.now();
+ return window.performance.now();
}
return Date.now();
}
