fix(sdk): stayIntervalMs边界守卫——0/NaN钳制下限防事件灌入

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-18 13:45:36 +08:00
parent d6b2289cee
commit 25e37f56dc
2 changed files with 33 additions and 1 deletions
+3 -1
View File
@@ -24,7 +24,9 @@ export interface StayOptions {
}
export function startStayTracking(t: Transport, ps: PageSession, opts: StayOptions = {}): void {
const stayIntervalMs = opts.stayIntervalMs ?? 15_000;
// 边界守卫:0/负数等有限小值钳制下限 1s(防 setInterval 高频 cut 灌入事件);
// NaN/Infinity 非有限值——NaN 绕过 ?? 的 nullish 判定直传,须显式回落默认 15s。
const stayIntervalMs = Math.max(1_000, Number.isFinite(opts.stayIntervalMs) ? opts.stayIntervalMs! : 15_000);
let intervalStart: number | null = null; // performance.now 基准;null=无 open 区间
let lastCutEnd: number | null = null; // 最近一次 cut 的 perf 端点——重开回溯的钳制上界
let lastAct = Date.now(); // 墙钟活动戳(沿 events.ts 冻结语义;页面加载即活动)