: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(session-replay): stop held keys firing hotkeys per OS repeat (#87255)
posthog[bot]7db048d2db56
diff --git a/frontend/src/lib/hooks/useKeyboardHotkeys.test.tsx b/frontend/src/lib/hooks/useKeyboardHotkeys.test.tsxindex 6a9221a276fe..4f942ad93a76 100644--- a/frontend/src/lib/hooks/useKeyboardHotkeys.test.tsx+++ b/frontend/src/lib/hooks/useKeyboardHotkeys.test.tsx@@ -79,9 +79,21 @@ describe('useKeyboardHotkeys', () => {})})- it('does not capture held-key repeats but still runs the action', () => {+ it('runs the action once when a key is held, ignoring OS repeats', () => {const action = jest.fn()- renderHook(() => useKeyboardHotkeys({ arrowleft: { action, willHandleEvent: true } }))+ renderHook(() => useKeyboardHotkeys({ s: { action } }))++ press('s')+ press('s', { repeat: true })+ press('s', { repeat: true })++ expect(action).toHaveBeenCalledTimes(1)+ expect(mockPosthog.capture).toHaveBeenCalledTimes(1)+ })++ it('re-runs the action on repeats for allowRepeat hotkeys but still captures once', () => {+ const action = jest.fn()+ renderHook(() => useKeyboardHotkeys({ arrowleft: { action, willHandleEvent: true, allowRepeat: true } }))press('ArrowLeft')press('ArrowLeft', { repeat: true })diff --git a/frontend/src/lib/hooks/useKeyboardHotkeys.tsx b/frontend/src/lib/hooks/useKeyboardHotkeys.tsxindex a4fd74fce578..21f218540f9b 100644--- a/frontend/src/lib/hooks/useKeyboardHotkeys.tsx+++ b/frontend/src/lib/hooks/useKeyboardHotkeys.tsx@@ -10,6 +10,9 @@ export interface HotkeyInterface {disabled?: boolean// Indicates the "action" will handle the event and preventDefault should not be calledwillHandleEvent?: boolean+ // Run the action again on each OS key-repeat event while the key is held. Off by default so a+ // held key fires the action once; opt in for seek-style shortcuts that should repeat (arrow keys).+ allowRepeat?: boolean}export type HotkeysInterface = Partial<Record<HotKey, HotkeyInterface>>@@ -95,6 +98,12 @@ export function useKeyboardHotkeys(hotkeys: HotkeysInterface, deps?: DependencyLif (!hotkey.willHandleEvent) {event.preventDefault()}+ // Skip the action on held-key repeats unless the hotkey opts in. This stops a+ // resting key from firing an action per OS repeat event (e.g. one server-side+ // screenshot export per repeat for the replay player's "s" shortcut).+ if (event.repeat && !hotkey.allowRepeat) {+ break+ }// don't capture: when posthog is uninitialized (the toolbar bundle on customer sites — capturing// there only warns in the customer's console), on held-key repeats (seeking by holding an arrow// counts once), or on ctrl/meta chords reaching willHandleEvent actions (they treat those asdiff --git a/frontend/src/scenes/session-recordings/player/PurePlayer.tsx b/frontend/src/scenes/session-recordings/player/PurePlayer.tsxindex a032c694d285..464a9f48cb4a 100644--- a/frontend/src/scenes/session-recordings/player/PurePlayer.tsx+++ b/frontend/src/scenes/session-recordings/player/PurePlayer.tsx@@ -214,6 +214,7 @@ export function PurePlayer({ noMeta = false, noBorder = false }: PurePlayerPropsseekBackward(e.altKey ? ONE_SECOND_MS : undefined)},willHandleEvent: true,+ allowRepeat: true,},arrowright: {action: (e) => {@@ -225,6 +226,7 @@ export function PurePlayer({ noMeta = false, noBorder = false }: PurePlayerPropsseekForward(e.altKey ? ONE_SECOND_MS : undefined)},willHandleEvent: true,+ allowRepeat: true,},...speedHotkeys,...(isFullScreen ? { escape: { action: () => setIsFullScreen(false) } } : {}),diff --git a/products/logs/frontend/components/LogsViewer/LogsViewer.tsx b/products/logs/frontend/components/LogsViewer/LogsViewer.tsxindex 51e9b88c7301..c42206015347 100644--- a/products/logs/frontend/components/LogsViewer/LogsViewer.tsx+++ b/products/logs/frontend/components/LogsViewer/LogsViewer.tsx@@ -223,10 +223,10 @@ function LogsViewerContent({useKeyboardHotkeys({- arrowdown: { action: handleMoveDown, disabled: !keyboardNavEnabled },- j: { action: handleMoveDown, disabled: !keyboardNavEnabled },- arrowup: { action: handleMoveUp, disabled: !keyboardNavEnabled },- k: { action: handleMoveUp, disabled: !keyboardNavEnabled },+ arrowdown: { action: handleMoveDown, disabled: !keyboardNavEnabled, allowRepeat: true },+ j: { action: handleMoveDown, disabled: !keyboardNavEnabled, allowRepeat: true },+ arrowup: { action: handleMoveUp, disabled: !keyboardNavEnabled, allowRepeat: true },+ k: { action: handleMoveUp, disabled: !keyboardNavEnabled, allowRepeat: true },// arrowleft, arrowright, h, l handled by native keydown/keyup for smooth 60fps scrollingenter: {action: () => {