Skip to content

Commit c787e65

Browse files
committed
fix(poll): adds NaN guard for event ID parsing
Wraps all parseInt(id, 10) calls in eventIdNum() helper that returns 0 for non-numeric IDs. Prevents _lastEventId from becoming 'NaN' if GitHub ever returned a non-numeric event ID, which would permanently break change detection until the next full refresh.
1 parent 87a2cd4 commit c787e65

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/app/services/events.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ export const ACTIONABLE_EVENT_TYPES = [
3434

3535
// ── Module-level state ───────────────────────────────────────────────────────
3636

37+
function eventIdNum(id: string): number {
38+
const n = parseInt(id, 10);
39+
return Number.isNaN(n) ? 0 : n;
40+
}
41+
3742
let _lastEventId: string | null = null;
3843

3944
// ── Auth cleanup ──────────────────────────────────────────────────────────────
@@ -74,8 +79,8 @@ export async function fetchUserEvents(
7479
let lastPageEvents = allEvents;
7580
while (lastPageEvents.length === 100 && page <= 3) {
7681
if (_lastEventId !== null) {
77-
const threshold = parseInt(_lastEventId, 10);
78-
if (lastPageEvents.some((e) => parseInt(e.id, 10) <= threshold)) break;
82+
const threshold = eventIdNum(_lastEventId);
83+
if (lastPageEvents.some((e) => eventIdNum(e.id) <= threshold)) break;
7984
}
8085
try {
8186
const next = await octokit.request("GET /users/{username}/events", {
@@ -95,7 +100,7 @@ export async function fetchUserEvents(
95100
}
96101

97102
const maxId = allEvents.reduce(
98-
(max, e) => Math.max(max, parseInt(e.id, 10)),
103+
(max, e) => Math.max(max, eventIdNum(e.id)),
99104
0,
100105
);
101106

@@ -108,9 +113,9 @@ export async function fetchUserEvents(
108113
}
109114

110115
// Subsequent calls: filter to only events newer than _lastEventId
111-
const lastIdNum = parseInt(_lastEventId, 10);
116+
const lastIdNum = eventIdNum(_lastEventId);
112117
const newEvents = allEvents.filter(
113-
(e) => parseInt(e.id, 10) > lastIdNum,
118+
(e) => eventIdNum(e.id) > lastIdNum,
114119
);
115120

116121
if (maxId > lastIdNum) {

0 commit comments

Comments
 (0)