Skip to content

Commit

Permalink
fix: performance downgrade in node env (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lmmmmmm-bb authored Feb 15, 2023
1 parent 63bf34f commit a90b825
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/runtime/shared/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import type { HookInfo } from '../../types'
export function setupHooksDebug<T extends Hookable<any>>(hooks: T) {
const serverHooks: Record<string, HookInfo> = {}

// maybe run in node or browser env
// performance api is not supported below node version v16.0.0
// browser support https://caniuse.com/mdn-api_performance
// if `performance` is undefined then downgrade to `Date`
// eslint-disable-next-line no-constant-condition
const now = typeof 'performance' === 'undefined'
? () => window.performance.now()
: () => Date.now()
const now = typeof globalThis.performance === 'undefined'
? () => Date.now()
: () => performance.now()

hooks.beforeEach((event) => {
if (!serverHooks[event.name]) {
Expand Down

0 comments on commit a90b825

Please sign in to comment.