From 521ab4a6e6d66201ac729747f03f75d4c33c520e Mon Sep 17 00:00:00 2001 From: Pavan Kumar VH Date: Thu, 3 Sep 2026 15:15:57 +0530 Subject: [PATCH] Fix NaN handling in getResponseAdForSlot The function didn't validate that slotIndex is a finite number. If slotIndex was NaN or Infinity, Math.floor(NaN) would return NaN, causing Math.max(0, NaN) to return NaN, and NaN % ads.length to return NaN. Added Number.isFinite() check to default to 0 for invalid numbers. --- common/src/util/lazy-response-ads.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/src/util/lazy-response-ads.ts b/common/src/util/lazy-response-ads.ts index 1b491a44d8..2b263c9d5f 100644 --- a/common/src/util/lazy-response-ads.ts +++ b/common/src/util/lazy-response-ads.ts @@ -29,7 +29,8 @@ export function getResponseAdForSlot( slotIndex: number, ): T | undefined { if (ads.length === 0) return undefined - return ads[Math.max(0, Math.floor(slotIndex)) % ads.length] + const safeSlotIndex = Number.isFinite(slotIndex) ? slotIndex : 0 + return ads[Math.max(0, Math.floor(safeSlotIndex)) % ads.length] } export function createLazyResponseAdQueue<