vercel / speed-insights

Vercel Speed Insights package
https://vercel.com/docs/speed-insights
Apache License 2.0
54 stars 6 forks source link

SvelteKit - TypeError: Cannot Read properties of undefined (reading: 'id") #27

Closed ninicdennis closed 7 months ago

ninicdennis commented 7 months ago

When including the new speed insights package into my application, Inside of the app, content stops loading and I see the following error 3 times in my console:

TypeError: Cannot read properties of undefined (reading 'id')
    at injectSpeedInsights2 (@vercel_speed-insights_sveltekit.js?v=49aa9ded:88:41)
    at +layout.ts:5:1

The application does have analytics and speed insights both enabled.

feugy commented 7 months ago

Hello @ninicdennis, and thanks for the feedback. In order to help us fixing it as quickly as possible, could you share a minimal reproduction please?

DanielRios549 commented 7 months ago

Same problem here. I just did what is said in the documentation, add the following code to +layout.ts file:

import { injectSpeedInsights } from '@vercel/speed-insights/sveltekit'
injectSpeedInsights()

One thing I notice: The error occurs when I call the injectSpeedInsights() function in +layout.ts file, if I call it inside a onMount() function in +layout.svelte, it runs successfully. +layout.ts file runs in both server and client, but it shows error in the client as well, the error that is not shown in onMount() function. Don't know why.

feugy commented 7 months ago

Than you gents. we indeed always tried it in the <script> markup of a +layout.svelte component. The fix is on its way, please bear with me.

feugy commented 7 months ago

@DanielRios549 and @ninicdennis, would you mind trying version 1.0.1 please?

DanielRios549 commented 7 months ago

@feugy Version 1.0.1 fix the error for me. Thank you so much.

ninicdennis commented 7 months ago

@feugy Verified on my end its working as intended! Thank you!