Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(replay): avoid stack overflow when spreading large snapshot arrays (#63204)

Xanderd1de55362a16
diff --git a/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.ts b/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.ts
index 1c3cf8e0b644..5f9bc07a07be 100644
--- a/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.ts
+++ b/frontend/src/scenes/session-recordings/player/inspector/playerInspectorLogic.ts
@@ -896,11 +896,17 @@ export const playerInspectorLogic = kea<playerInspectorLogicType>([
})
})
- // Add all pre-processed context items at once
- items.push(...(processedSnapshotData?.contextItems || []))
+ // Add all pre-processed context items
+ // NOTE: not `items.push(...array)` — spreading an unbounded array into a call
+ // blows the argument stack (RangeError) on very large recordings
+ for (const item of processedSnapshotData?.contextItems || []) {
+ items.push(item)
+ }
// Add runtime doctor events (asset errors, rrweb warnings)
- items.push(...runtimeDoctorEvents)
+ for (const item of runtimeDoctorEvents) {
+ items.push(item)
+ }
// now we've calculated everything else,
// we always start with a context row
diff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts
index 135c3ba175ac..65f1e94d0b6c 100644
--- a/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts
+++ b/frontend/src/scenes/session-recordings/player/sessionRecordingPlayerLogic.ts
@@ -1643,7 +1643,11 @@ export const sessionRecordingPlayerLogic = kea<sessionRecordingPlayerLogicType>(
if (values.currentSegment?.windowId !== undefined) {
const allSnapshots = values.sessionPlayerData.snapshotsByWindowId[values.currentSegment?.windowId] ?? []
- eventsToAdd.push(...findNewEvents(allSnapshots, currentEvents))
+ // NOTE: not `push(...array)` — spreading an unbounded snapshot array into a call
+ // blows the argument stack (RangeError) on very large recordings
+ for (const event of findNewEvents(allSnapshots, currentEvents)) {
+ eventsToAdd.push(event)
+ }
}
// If replayer isn't initialized, it will be initialized with the already loaded snapshots.