Skip to content

Commit 3bbbfc7

Browse files
committed
fix "Cannot read properties of undefined"
1 parent b8225b2 commit 3bbbfc7

File tree

6 files changed

+23
-14
lines changed

6 files changed

+23
-14
lines changed

app/components/insights-carousel.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ const InsightsCarousel = () => {
5757
return;
5858
}
5959

60-
setCount(api.scrollSnapList().length);
60+
const scrollSnapList = api.scrollSnapList();
61+
setCount(scrollSnapList?.length ?? 0);
6162
setCurrent(api.selectedScrollSnap() + 1);
6263

6364
api.on('select', () => {

app/profile/[login]/repositories/components/user-contributions-list.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ export const UserContributionsList: FC<UserContributionsListProps> = ({
6767
<TimelineItem key={contribution.year}>
6868
<TimelineTime>
6969
{contribution.year}
70-
{contributionCount ? ` • ${contribution.data.length} repositories` : ''}
70+
{contributionCount ? ` • ${contribution.data?.length ?? 0} repositories` : ''}
7171
</TimelineTime>
7272
<TimelineDescription>
73-
{contribution.data.map((item) => (
73+
{contribution.data?.map((item) => (
7474
<ContributionRepositoryCard
7575
key={item.repository?.name}
7676
repository={item.repository}

app/profile/[login]/seo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type DataType = NonNullable<PageProfileOverviewQuery['user']>;
88
type LanguagesType = NonNullable<PageProfileLanguagesQuery['user']>['languages'];
99

1010
const clip = (t: string, max = 158) => {
11-
if (t.length <= max) return t;
11+
if (!t || t.length <= max) return t;
1212
const cut = t.slice(0, max - 1);
1313
const i = cut.lastIndexOf(' ');
1414
return `${i > 80 ? cut.slice(0, i) : cut}…`;

badge/templates/inline/inline.styles.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ const getCommonStyles = (backgroundColor: string) => ({
3232
textShadow: getTextShadow(backgroundColor),
3333
});
3434

35-
export const getLabelStyles = (backgroundColor = LABEL_BG) => ({
36-
...getCommonStyles(backgroundColor),
35+
export const getLabelStyles = (backgroundColor?: string) => ({
36+
...getCommonStyles(backgroundColor ?? LABEL_BG),
3737
fontSize: `${FONT_SCALE}em`,
3838
});
3939

40-
export const getValueStyles = (backgroundColor = VALUE_BG) => ({
41-
...getCommonStyles(backgroundColor),
40+
export const getValueStyles = (backgroundColor?: string) => ({
41+
...getCommonStyles(backgroundColor ?? VALUE_BG),
4242
fontSize: `${FONT_SCALE}em`,
4343
});
4444

45-
export const getMetaStyles = (backgroundColor = VALUE_BG) => ({
46-
...getCommonStyles(backgroundColor),
45+
export const getMetaStyles = (backgroundColor?: string) => ({
46+
...getCommonStyles(backgroundColor ?? VALUE_BG),
4747
opacity: 0.9,
4848
fontSize: `${META_SCALE}em`,
4949
borderLeft: '1px solid rgba(255, 255, 255, 0.3)',

badge/utils/get-contrast-text-color.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
export function getContrastTextColor(bgColor: string): 'black' | 'white' {
2+
// Handle undefined/null/empty values
3+
if (!bgColor || typeof bgColor !== 'string') {
4+
return 'black'; // Default to black text on white background
5+
}
6+
27
// Remove '#' if present
38
let hex = bgColor.replace('#', '');
49

badge/utils/get-latest-snapshot.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import type { User } from '@/types/generated/graphql';
22

33
export const getLatestSnapshot = (snapshots: User['snapshots']): User['snapshots'][string] | null => {
4+
if (!snapshots || typeof snapshots !== 'object') {
5+
return null;
6+
}
7+
48
const dates = Object.keys(snapshots);
59
if (!dates.length) {
610
return null;
711
}
812

913
// Sort date strings ascending
10-
const sortedDates = dates.sort((a, b) => new Date(a).getTime() - new Date(b).getTime());
11-
12-
const latestDate = sortedDates[sortedDates.length - 1];
14+
const sortedDates = dates.toSorted((a, b) => new Date(a).getTime() - new Date(b).getTime());
1315

14-
return snapshots[latestDate];
16+
const latestDate = sortedDates.at(-1);
17+
return latestDate ? snapshots[latestDate] : null;
1518
};

0 commit comments

Comments
 (0)