Patch performance measure and ignore nova calendar
This commit is contained in:
parent
d8eb38fe52
commit
003d068c56
3 changed files with 47 additions and 3 deletions
8
.gitignore
vendored
8
.gitignore
vendored
|
|
@ -24,9 +24,11 @@
|
||||||
.DS_Store
|
.DS_Store
|
||||||
*.pem
|
*.pem
|
||||||
*.sqlite
|
*.sqlite
|
||||||
|
# external experiments
|
||||||
# debug
|
nova-calendar-main/
|
||||||
npm-debug.log*
|
|
||||||
|
# debug
|
||||||
|
npm-debug.log*
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
.pnpm-debug.log*
|
.pnpm-debug.log*
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import "@/lib/performance-measure-polyfill"
|
||||||
import type { Metadata } from "next"
|
import type { Metadata } from "next"
|
||||||
import "./globals.css"
|
import "./globals.css"
|
||||||
import { ConvexClientProvider } from "./ConvexClientProvider"
|
import { ConvexClientProvider } from "./ConvexClientProvider"
|
||||||
|
|
|
||||||
41
src/lib/performance-measure-polyfill.ts
Normal file
41
src/lib/performance-measure-polyfill.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
export {}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
var __performanceMeasurePatched: boolean | undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
function isNegativeTimestampError(error: unknown): boolean {
|
||||||
|
if (!(error instanceof Error)) return false
|
||||||
|
return error.message.toLowerCase().includes("cannot have a negative time stamp")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof performance !== "undefined" && typeof performance.measure === "function") {
|
||||||
|
if (!globalThis.__performanceMeasurePatched) {
|
||||||
|
const originalMeasure = performance.measure.bind(performance)
|
||||||
|
performance.measure = ((name: string, startOrOptions?: string | PerformanceMeasureOptions, endMark?: string) => {
|
||||||
|
try {
|
||||||
|
return originalMeasure(name, startOrOptions as string | PerformanceMeasureOptions, endMark)
|
||||||
|
} catch (error) {
|
||||||
|
if (!isNegativeTimestampError(error)) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next.js occasionally triggers an invalid interval when profiling slow routes.
|
||||||
|
// Clamp the measurement to start at 0 to avoid crashing the page.
|
||||||
|
if (typeof startOrOptions === "object" && startOrOptions) {
|
||||||
|
const safeOptions: PerformanceMeasureOptions = {
|
||||||
|
...startOrOptions,
|
||||||
|
start: 0,
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return originalMeasure(name, safeOptions, endMark)
|
||||||
|
} catch {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
}) as typeof performance.measure
|
||||||
|
globalThis.__performanceMeasurePatched = true
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue