@@ -21,6 +21,9 @@ import type { FullTabProps } from "../utils/types";
2121import { getCountryCode , getCountryName } from "@databuddy/shared" ;
2222
2323const getPerformanceRating = ( score : number ) : { rating : string ; className : string } => {
24+ if ( typeof score !== "number" || Number . isNaN ( score ) ) {
25+ return { rating : "Unknown" , className : "text-muted-foreground" } ;
26+ }
2427 if ( score >= 90 ) return { rating : "Excellent" , className : "text-green-500" } ;
2528 if ( score >= 70 ) return { rating : "Good" , className : "text-green-500" } ;
2629 if ( score >= 50 ) return { rating : "Moderate" , className : "text-yellow-500" } ;
@@ -337,14 +340,23 @@ export function WebsitePerformanceTab({
337340 } ;
338341
339342 const getRegionCountryIcon = ( name : string ) => {
343+ if ( typeof name !== "string" || ! name . includes ( "," ) ) {
344+ return < CountryFlag country = { "" } size = { 16 } /> ;
345+ }
340346 const countryPart = name . split ( "," ) [ 1 ] ?. trim ( ) ;
341347 const code = getCountryCode ( countryPart || "" ) ;
342348 return < CountryFlag country = { code } size = { 16 } /> ;
343349 } ;
344350
345351 const formatRegionName = ( name : string ) => {
352+ if ( typeof name !== "string" || ! name . includes ( "," ) ) {
353+ return name || "Unknown region" ;
354+ }
346355 const [ region , countryPart ] = name . split ( "," ) . map ( s => s . trim ( ) ) ;
347- const code = getCountryCode ( countryPart || "" ) ;
356+ if ( ! region || ! countryPart ) {
357+ return name || "Unknown region" ;
358+ }
359+ const code = getCountryCode ( countryPart ) ;
348360 const countryName = getCountryName ( code ) ;
349361 if ( countryName && region && countryName . toLowerCase ( ) === region . toLowerCase ( ) ) {
350362 return countryName ;
0 commit comments