-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add wrapper for performance.now and bump packages to beta test vercel…
… edge function support
- Loading branch information
Showing
5 changed files
with
29 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
const START = Date.now(); | ||
|
||
/** | ||
* Utility function for using the performance.now() function if it exists, otherwise | ||
* falls back to Date.now() - START, which has less precision but shouldn't matter for us. | ||
* | ||
* @note - This is required for compatibility with the Vercel Edge Function Runtime | ||
*/ | ||
export function now() { | ||
if (hasPerformanceNow()) { | ||
return performance.now(); | ||
} | ||
|
||
|
||
return Date.now() - START; | ||
} | ||
|
||
function hasPerformanceNow() { | ||
return typeof performance !== "undefined" && "now" in performance && typeof performance.now === "function"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters