Patch performance measure and ignore nova calendar

This commit is contained in:
Esdras Renan 2025-11-08 00:36:24 -03:00
parent d8eb38fe52
commit 003d068c56
3 changed files with 47 additions and 3 deletions

2
.gitignore vendored
View file

@ -24,6 +24,8 @@
.DS_Store
*.pem
*.sqlite
# external experiments
nova-calendar-main/
# debug
npm-debug.log*

View file

@ -1,3 +1,4 @@
import "@/lib/performance-measure-polyfill"
import type { Metadata } from "next"
import "./globals.css"
import { ConvexClientProvider } from "./ConvexClientProvider"

View 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
}
}