vercel / speed-insights

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

fix(#56,#72): useSearchParams might return null and break script insertion #73

Closed feugy closed 3 months ago

feugy commented 3 months ago

๐Ÿ““ What's in there?

Under some circumstances with pages router (some Next.js versions, env variable or depending on where the component is mounted), the following error is thrown when rendering SpeedInsights Next.js component:

TypeError: searchParams.entries is not a function
    at useRoute (file:///node_modules/.pnpm/@vercel+speed-insights@1.0.11_next@14.2.3_react@18.3.1/node_modules/@vercel/speed-insights/dist/next/index.mjs:151:40)
    at SpeedInsightsComponent (file:///node_modules/.pnpm/@vercel+speed-insights@1.0.11_next@14.2.3_react@18.3.1/node_modules/@vercel/speed-insights/dist/next/index.mjs:159:17)
    at renderWithHooks (/node_modules/.pnpm/react-dom@18.3.1_react@18.3.1/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5658:16)
    at renderIndeterminateComponent (/node_modules/.pnpm/react-dom@18.3.1_react@18.3.1/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5732:1

This PR fixes it, but providing a default empty search param object.

๐Ÿงช How to test?

Tested with:

vercel[bot] commented 3 months ago

The latest updates on your projects. Learn more about Vercel for Git โ†—๏ธŽ

Name Status Preview Comments Updated (UTC)
speed-insights-astro โœ… Ready (Inspect) Visit Preview ๐Ÿ’ฌ Add feedback Jun 12, 2024 7:55am
speed-insights-nextjs โœ… Ready (Inspect) Visit Preview ๐Ÿ’ฌ Add feedback Jun 12, 2024 7:55am
speed-insights-nuxt โœ… Ready (Inspect) Visit Preview ๐Ÿ’ฌ Add feedback Jun 12, 2024 7:55am
speed-insights-remix โœ… Ready (Inspect) Visit Preview ๐Ÿ’ฌ Add feedback Jun 12, 2024 7:55am
speed-insights-sveltekit โœ… Ready (Inspect) Visit Preview ๐Ÿ’ฌ Add feedback Jun 12, 2024 7:55am
speed-insights-vue โœ… Ready (Inspect) Visit Preview ๐Ÿ’ฌ Add feedback Jun 12, 2024 7:55am
socket-security[bot] commented 3 months ago

New and removed dependencies detected. Learn more about Socket for GitHub โ†—๏ธŽ

Package New capabilities Transitives Size Publisher
npm/@vercel/speed-insights@1.0.12 None 0 0 B

๐Ÿšฎ Removed packages: npm/@vercel/speed-insights@1.0.11

View full reportโ†—๏ธŽ