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(logs): stop hidden viewer hotkeys swallowing sql editor keys (#123891)

Christiaan Hendriksen00c9ee8e882d
diff --git a/frontend/src/lib/hooks/useKeyboardHotkeys.test.tsx b/frontend/src/lib/hooks/useKeyboardHotkeys.test.tsx
index 4f942ad93a76..bd12343a527a 100644
--- a/frontend/src/lib/hooks/useKeyboardHotkeys.test.tsx
+++ b/frontend/src/lib/hooks/useKeyboardHotkeys.test.tsx
@@ -149,14 +149,21 @@ describe('useKeyboardHotkeys', () => {
expect(mockPosthog.capture).not.toHaveBeenCalled()
})
- it('does not run or capture while typing in an input', () => {
+ it.each([
+ ['an input', '<input data-target />'],
+ [
+ 'an EditContext Monaco editor',
+ '<div class="monaco-editor"><div class="native-edit-context" tabindex="0" data-target></div></div>',
+ ],
+ ])('does not run or capture while typing in %s', (_, markup) => {
const action = jest.fn()
renderHook(() => useKeyboardHotkeys({ k: { action } }))
- const input = document.createElement('input')
- document.body.appendChild(input)
- press('k', {}, input)
- input.remove()
+ const host = document.createElement('div')
+ host.innerHTML = markup
+ document.body.appendChild(host)
+ press('k', {}, host.querySelector('[data-target]') as Element)
+ host.remove()
expect(action).not.toHaveBeenCalled()
expect(mockPosthog.capture).not.toHaveBeenCalled()
diff --git a/frontend/src/lib/hooks/useKeyboardHotkeys.tsx b/frontend/src/lib/hooks/useKeyboardHotkeys.tsx
index 21f218540f9b..6967165bc785 100644
--- a/frontend/src/lib/hooks/useKeyboardHotkeys.tsx
+++ b/frontend/src/lib/hooks/useKeyboardHotkeys.tsx
@@ -77,7 +77,8 @@ export function useKeyboardHotkeys(hotkeys: HotkeysInterface, deps?: DependencyL
// Ignore typing on inputs (default behavior); except Esc key
const isDOMInput =
IGNORE_INPUTS.includes((event.target as HTMLElement).tagName.toLowerCase()) ||
- (event.target as HTMLElement).isContentEditable
+ (event.target as HTMLElement).isContentEditable ||
+ (event.target as HTMLElement).closest('.monaco-editor') !== null
if (key !== 'Escape' && (isDOMInput || isToolbarInput(event, IGNORE_INPUTS))) {
return
}
diff --git a/products/logs/frontend/LogsScene.tsx b/products/logs/frontend/LogsScene.tsx
index 4ec65df02f97..6df936cd5e95 100644
--- a/products/logs/frontend/LogsScene.tsx
+++ b/products/logs/frontend/LogsScene.tsx
@@ -92,7 +92,11 @@ const LogsSceneTabbedContent = (): JSX.Element => {
should not replay the initial loading animation. */}
<div className={cn('flex flex-col flex-1 min-h-0', activeTab !== 'viewer' && 'hidden')}>
<div className="flex flex-col gap-2 py-2 flex-1 min-h-0">
- <LogsViewer id={LOGS_SCENE_VIEWER_ID} showSavedViewsButton />
+ <LogsViewer
+ id={LOGS_SCENE_VIEWER_ID}
+ showSavedViewsButton
+ keyboardShortcutsEnabled={activeTab === 'viewer'}
+ />
</div>
</div>
{showServices && showServicesV2 && <LogsServicesV2 />}
diff --git a/products/logs/frontend/components/LogsViewer/LogsViewer.tsx b/products/logs/frontend/components/LogsViewer/LogsViewer.tsx
index 718c51518f56..5f01a085c4f6 100644
--- a/products/logs/frontend/components/LogsViewer/LogsViewer.tsx
+++ b/products/logs/frontend/components/LogsViewer/LogsViewer.tsx
@@ -55,6 +55,7 @@ export interface LogsViewerProps {
defaultSparklineCollapsed?: boolean
// A panel embedded under other keyboard controls leaves focus where it is.
autoFocusSearch?: boolean
+ keyboardShortcutsEnabled?: boolean
}
export function LogsViewer({
@@ -68,6 +69,7 @@ export function LogsViewer({
defaultFacetRailCollapsed,
defaultSparklineCollapsed,
autoFocusSearch = true,
+ keyboardShortcutsEnabled = true,
}: LogsViewerProps): JSX.Element {
return (
<BindLogic logic={logsViewerFiltersLogic} props={{ id, initialFilters, pinnedFilters, personId, sessionId }}>
@@ -84,6 +86,7 @@ export function LogsViewer({
showFullScreenButton={showFullScreenButton}
showSavedViewsButton={showSavedViewsButton}
autoFocusSearch={autoFocusSearch}
+ keyboardShortcutsEnabled={keyboardShortcutsEnabled}
scope={{ initialFilters, pinnedFilters, personId, sessionId }}
/>
</BindLogic>
@@ -108,11 +111,13 @@ function LogsViewerContent({
showFullScreenButton,
showSavedViewsButton,
autoFocusSearch,
+ keyboardShortcutsEnabled,
scope,
}: {
showFullScreenButton: boolean
showSavedViewsButton: boolean
autoFocusSearch: boolean
+ keyboardShortcutsEnabled: boolean
scope: LogsViewerScope
}): JSX.Element {
const {
@@ -197,7 +202,7 @@ function LogsViewerContent({
// Handle keyboard scroll with keydown/keyup for smooth 60fps scrolling
useEffect(() => {
- if (!isFocused || wrapBody || isTraceDialogOpen) {
+ if (!keyboardShortcutsEnabled || !isFocused || wrapBody || isTraceDialogOpen) {
return
}
@@ -228,7 +233,7 @@ function LogsViewerContent({
window.removeEventListener('keyup', handleKeyUp)
stopScrolling()
}
- }, [isFocused, wrapBody, isTraceDialogOpen, startScrolling, stopScrolling])
+ }, [keyboardShortcutsEnabled, isFocused, wrapBody, isTraceDialogOpen, startScrolling, stopScrolling])
const tzLabelFormat: Pick<TZLabelProps, 'formatDate' | 'formatTime' | 'displayTimezone'> = {
formatDate: 'YYYY-MM-DD',
@@ -251,8 +256,8 @@ function LogsViewerContent({
)
// The trace dialog opens over the viewer, so the viewer's keys stop while it is open.
- const listKeysEnabled = keyboardNavEnabled && !isTraceDialogOpen
- const focusedListKeysEnabled = isFocused && !isTraceDialogOpen
+ const listKeysEnabled = keyboardShortcutsEnabled && keyboardNavEnabled && !isTraceDialogOpen
+ const focusedListKeysEnabled = keyboardShortcutsEnabled && isFocused && !isTraceDialogOpen
useKeyboardHotkeys(
{
@@ -307,6 +312,7 @@ function LogsViewerContent({
},
},
[
+ keyboardShortcutsEnabled,
isFocused,
keyboardNavEnabled,
isTraceDialogOpen,