Merged in fix/tracking-issue (pull request #1643)

Fix/tracking issue: add try/catch around promises

* Test

* Cleaning


Approved-by: Anton Gunnarsson
This commit is contained in:
Linus Flood
2025-03-26 12:59:59 +00:00
parent ca23589f88
commit ddefe2e59b
2 changed files with 16 additions and 5 deletions

View File

@@ -7,6 +7,7 @@ import { getProfile } from "@/lib/trpc/memoizedRequests"
import { auth } from "@/auth" import { auth } from "@/auth"
import { getIntl } from "@/i18n" import { getIntl } from "@/i18n"
import { getLang } from "@/i18n/serverContext" import { getLang } from "@/i18n/serverContext"
import { isValidSession } from "@/utils/session"
export async function ProtectedLayout({ children }: React.PropsWithChildren) { export async function ProtectedLayout({ children }: React.PropsWithChildren) {
const intl = await getIntl() const intl = await getIntl()
@@ -22,7 +23,7 @@ export async function ProtectedLayout({ children }: React.PropsWithChildren) {
const redirectURL = `/${getLang()}/login?redirectTo=${redirectTo}` const redirectURL = `/${getLang()}/login?redirectTo=${redirectTo}`
if (!session) { if (!isValidSession(session)) {
console.log(`[layout:protected] no session, redirecting to: ${redirectURL}`) console.log(`[layout:protected] no session, redirecting to: ${redirectURL}`)
redirect(redirectURL) redirect(redirectURL)
} }

View File

@@ -93,10 +93,20 @@ export default function RouterTransition({
} }
const trackPerformance = async () => { const trackPerformance = async () => {
const [pageLoadTime, lcpTime] = await Promise.all([ let pageLoadTime: number | undefined = undefined
promiseWithTimeout(getPageLoadTimeEntry(), 3000), let lcpTime: number | undefined = undefined
promiseWithTimeout(getLCPTimeEntry(), 3000),
]) try {
pageLoadTime = await promiseWithTimeout(getPageLoadTimeEntry(), 3000)
} catch (error) {
console.error("Error obtaining pageLoadTime:", error)
}
try {
lcpTime = await promiseWithTimeout(getLCPTimeEntry(), 3000)
} catch (error) {
console.error("Error obtaining lcpTime:", error)
}
const trackingData = { const trackingData = {
...pageData, ...pageData,