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.

chore(et): simplify exception card state (#79057)

Hugues Pouillotb522da2099ec
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 9ee2817e68ad..1d7f9fa38550 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -2085,9 +2085,9 @@ snapshots:
errortracking-contextdisplay--context-display-with-stacktrace--light:
hash: v1.k794b7964.4647fc443f0df7cf2451a05f28fb95592b4c40e98d59ae289a5a3a2d54dba14f.y3p3Lw9_WVMCUVwR_8JJwjdkKaYBWgrJNzCa3e3Mu2I
errortracking-exceptioncard--exception-card-all-events--dark:
- hash: v1.k794b7964.d8eeeb2edea49238f843906636f535de9d9bb972dfdb7b0a7d4996e2c90b8a09.x8dkCzh5Nu2XxKwjMs6ab8KHxvQaP9toxjiu3Cd0dNs
+ hash: v1.k794b7964.1ecdd072724548b5b1479b571c4e71d939c63eec086577ca404887e1a847d77e.sDYzU0ZZuvsAFJHS8-T1Kw9lrA-Pi64kJtUX8oILYu0
errortracking-exceptioncard--exception-card-all-events--light:
- hash: v1.k794b7964.c83f4ab40ac186ee8872b9e051f8eb74be9fe70a1f257d853bbbb8372f2d6db2.my2kxuXPuZRq6U3hYpzKMZOQiYOVGgYTFrYo97sltlo
+ hash: v1.k794b7964.1f130e815e8ad575ae002b76862cb638dd37f70c7cc5171f917026e4fde7c04e.2aVA113FgaOPAEfpNsaCysOoMkbGQGlpdryxOIaDfbk
errortracking-exceptioncard--exception-card-base--dark:
hash: v1.k794b7964.3c350c23790195a5fc0dfb048f81f0a62dee7d84dab927e4b0fe318adce3443c.uWybQFWQBqnNXQnYT_PSKs0VNv5dVHNtDFIkDAa1Toc
errortracking-exceptioncard--exception-card-base--light:
diff --git a/products/error_tracking/frontend/__mocks__/events/index.tsx b/products/error_tracking/frontend/__mocks__/events/index.tsx
index 3ae1f2708fa8..9120adae4e2c 100644
--- a/products/error_tracking/frontend/__mocks__/events/index.tsx
+++ b/products/error_tracking/frontend/__mocks__/events/index.tsx
@@ -1,5 +1,4 @@
-import { BindLogic, useActions } from 'kea'
-import { useEffect } from 'react'
+import { BindLogic } from 'kea'
import { errorPropertiesLogic } from 'lib/components/Errors/errorPropertiesLogic'
import { ErrorEventProperties } from 'lib/components/Errors/types'
@@ -48,14 +47,9 @@ export function ExceptionLogicWrapper({
loading?: boolean
children: JSX.Element
}): JSX.Element {
- const exceptionCardProps = { issueId: eventName }
+ const exceptionCardProps = { issueId: eventName, loading }
const properties = getEventProperties(eventName)
- const { setLoading } = useActions(exceptionCardLogic(exceptionCardProps))
-
- useEffect(() => {
- setLoading(loading)
- }, [loading, setLoading])
return (
<BindLogic logic={exceptionCardLogic} props={exceptionCardProps}>
diff --git a/products/error_tracking/frontend/components/ExceptionCard/ExceptionCard.stories.tsx b/products/error_tracking/frontend/components/ExceptionCard/ExceptionCard.stories.tsx
index d046487cebba..cd4baa1f520f 100644
--- a/products/error_tracking/frontend/components/ExceptionCard/ExceptionCard.stories.tsx
+++ b/products/error_tracking/frontend/components/ExceptionCard/ExceptionCard.stories.tsx
@@ -2,6 +2,8 @@ import { Meta } from '@storybook/react'
import { BindLogic, useActions } from 'kea'
import { useEffect } from 'react'
+import { LemonCard } from '@posthog/lemon-ui'
+
import { ErrorEventType } from 'lib/components/Errors/types'
import { mswDecorator } from '~/mocks/browser'
@@ -46,7 +48,7 @@ function asErrorEventType(event: unknown): ErrorEventType {
export function ExceptionCardBase(): JSX.Element {
return (
<div className="w-[1000px] h-[700px]">
- <BindLogic logic={exceptionCardLogic} props={{ issueId: 'issue-id' }}>
+ <BindLogic logic={exceptionCardLogic} props={{ issueId: 'issue-id', loading: false }}>
<OpenTimelineTab>
<ExceptionCard
issueId="issue-id"
@@ -233,7 +235,7 @@ function ExceptionCardSessionTimelineStory({
}): JSX.Element {
return (
<div className={containerClassName}>
- <BindLogic logic={exceptionCardLogic} props={{ issueId: 'issue-id' }}>
+ <BindLogic logic={exceptionCardLogic} props={{ issueId: 'issue-id', loading: false }}>
<OpenTimelineTab>
<ExceptionCard issueId="issue-id" issueName="Test Issue" loading={false} event={event} />
</OpenTimelineTab>
@@ -548,7 +550,7 @@ function buildSessionTimelineEvent(
}
function OpenTimelineTab({ children }: { children: JSX.Element }): JSX.Element {
- const { setCurrentTab } = useActions(exceptionCardLogic({ issueId: 'issue-id' }))
+ const { setCurrentTab } = useActions(exceptionCardLogic({ issueId: 'issue-id', loading: false }))
useEffect(() => {
setCurrentTab('timeline')
@@ -562,12 +564,18 @@ function OpenTimelineTab({ children }: { children: JSX.Element }): JSX.Element {
function ExceptionCardWrapperAllEvents({
children,
}: {
- children: (issueId: string, event: Partial<ErrorEventType>) => JSX.Element
+ children: (issueId: string, event: ErrorEventType) => JSX.Element
}): JSX.Element {
return (
- <div className="space-y-8">
- {Object.entries(TEST_EVENTS).map(([name, evt]: [string, any]) => {
- return <div key={name}>{children(name, evt)}</div>
+ <div className="space-y-4">
+ {Object.entries(TEST_EVENTS).map(([name, fixture]) => {
+ const event = { ...asErrorEventType(fixture), uuid: name }
+
+ return (
+ <LemonCard key={name} hoverEffect={false} className="h-96 w-[1000px] overflow-hidden p-0">
+ {children(name, event)}
+ </LemonCard>
+ )
})}
</div>
)
@@ -576,9 +584,7 @@ function ExceptionCardWrapperAllEvents({
export function ExceptionCardAllEvents(): JSX.Element {
return (
<ExceptionCardWrapperAllEvents>
- {(issueId, event) => (
- <ExceptionCard issueId={issueId} issueName={null} loading={false} event={event as ErrorEventType} />
- )}
+ {(issueId, event) => <ExceptionCard issueId={issueId} issueName={null} loading={false} event={event} />}
</ExceptionCardWrapperAllEvents>
)
}
diff --git a/products/error_tracking/frontend/components/ExceptionCard/ExceptionCard.tsx b/products/error_tracking/frontend/components/ExceptionCard/ExceptionCard.tsx
index aa798c948b0c..38158cbcd274 100644
--- a/products/error_tracking/frontend/components/ExceptionCard/ExceptionCard.tsx
+++ b/products/error_tracking/frontend/components/ExceptionCard/ExceptionCard.tsx
@@ -1,5 +1,5 @@
import { BindLogic, useActions, useValues } from 'kea'
-import { useEffect, useMemo, type CSSProperties } from 'react'
+import { useMemo, type CSSProperties } from 'react'
import { IconLogomark } from '@posthog/icons'
import { LemonCard } from '@posthog/lemon-ui'
@@ -41,22 +41,15 @@ export function ExceptionCard({
loading,
...contentProps
}: ExceptionCardProps): JSX.Element {
- const cardLogicProps = useMemo(() => ({ issueId }), [issueId])
- const { setLoading } = useActions(exceptionCardLogic(cardLogicProps))
+ const cardLogicProps = useMemo(() => ({ issueId, loading }), [issueId, loading])
- useEffect(() => {
- setLoading(loading)
- }, [setLoading, loading])
-
- const eventProps = useMemo(
- () =>
- ({
- properties: event?.properties,
- id: event?.uuid ?? issueId ?? 'error',
- timestamp: event?.timestamp,
- }) as ErrorPropertiesLogicProps,
- // eslint-disable-next-line react-hooks/exhaustive-deps
- [event?.uuid ?? issueId]
+ const eventProps = useMemo<ErrorPropertiesLogicProps>(
+ () => ({
+ properties: event?.properties,
+ id: event?.uuid ?? issueId,
+ timestamp: event?.timestamp,
+ }),
+ [event?.properties, event?.timestamp, event?.uuid, issueId]
)
const fingerprint = event?.properties?.$exception_fingerprint
@@ -90,7 +83,16 @@ function ExceptionCardContent({
<LemonCard hoverEffect={false} className="p-0 relative w-full h-full border-0 rounded-none flex flex-col">
<Tabs
value={currentTab}
- onValueChange={(value) => setCurrentTab(String(value))}
+ onValueChange={(value) => {
+ if (
+ value === 'stack_trace' ||
+ value === 'properties' ||
+ value === 'timeline' ||
+ value === 'recording'
+ ) {
+ setCurrentTab(value)
+ }
+ }}
className="flex min-h-0 flex-1 flex-col gap-0"
>
<div className="grid h-10 w-full shrink-0 grid-cols-[1fr_auto_1fr] items-center gap-2 border-b px-2">
diff --git a/products/error_tracking/frontend/components/ExceptionCard/Tabs/SessionTab/SessionRecordingTab.tsx b/products/error_tracking/frontend/components/ExceptionCard/Tabs/SessionTab/SessionRecordingTab.tsx
index 208109348871..e0f2c93aaedb 100644
--- a/products/error_tracking/frontend/components/ExceptionCard/Tabs/SessionTab/SessionRecordingTab.tsx
+++ b/products/error_tracking/frontend/components/ExceptionCard/Tabs/SessionTab/SessionRecordingTab.tsx
@@ -1,5 +1,4 @@
-import { useActions, useValues } from 'kea'
-import { useEffect } from 'react'
+import { useValues } from 'kea'
import { IconExternal } from '@posthog/icons'
import { LemonBanner } from '@posthog/lemon-ui'
@@ -22,25 +21,7 @@ export function SessionRecordingTab(): JSX.Element {
}
export function SessionRecordingContent(): JSX.Element {
- const {
- recordingProps,
- recordingTimestamp,
- isNotFound,
- sessionPlayerMetaDataLoading,
- isTimestampOutsideRecording,
- sessionId,
- } = useValues(sessionTabLogic)
- const { seekToTimestamp, setPlay } = useActions(sessionTabLogic)
-
- useEffect(() => {
- if (sessionPlayerMetaDataLoading || isNotFound) {
- return
- }
- if (recordingTimestamp) {
- seekToTimestamp(recordingTimestamp)
- }
- setPlay()
- }, [seekToTimestamp, recordingTimestamp, setPlay, isNotFound, sessionPlayerMetaDataLoading])
+ const { recordingProps, recordingTimestamp, isTimestampOutsideRecording, sessionId } = useValues(sessionTabLogic)
const replayUrl = urls.replaySingle(
sessionId,
diff --git a/products/error_tracking/frontend/components/ExceptionCard/Tabs/SessionTab/index.tsx b/products/error_tracking/frontend/components/ExceptionCard/Tabs/SessionTab/index.tsx
index acae55cd6376..6505ab098832 100644
--- a/products/error_tracking/frontend/components/ExceptionCard/Tabs/SessionTab/index.tsx
+++ b/products/error_tracking/frontend/components/ExceptionCard/Tabs/SessionTab/index.tsx
@@ -65,18 +65,24 @@ export function SessionTab({ timestamp, eventMarkerColor }: SessionTabProps): JS
))
.with([false, P.string], ([_, sessionId]) => (
<BindLogic logic={sessionTabLogic} props={{ timestamp, sessionId }}>
- <SessionTimelineTab eventMarkerColor={eventMarkerColor} />
+ <SessionTimelineTab timestamp={timestamp} eventMarkerColor={eventMarkerColor} />
<SessionRecordingTab />
</BindLogic>
))
.exhaustive()
}
-export function SessionTimelineTab({ eventMarkerColor }: { eventMarkerColor?: TimelineMarkerColor }): JSX.Element {
+export function SessionTimelineTab({
+ timestamp,
+ eventMarkerColor,
+}: {
+ timestamp?: string
+ eventMarkerColor?: TimelineMarkerColor
+}): JSX.Element {
const { properties, uuid } = useValues(errorPropertiesLogic)
const sessionTimelineRef = useRef<SessionTimelineHandle>(null)
const { currentTab } = useValues(exceptionCardLogic)
- const { sessionId, timestamp } = useValues(sessionTabLogic)
+ const { sessionId } = useValues(sessionTabLogic)
const { setRecordingTimestamp } = useActions(sessionTabLogic)
const { setCurrentTab } = useActions(exceptionCardLogic)
diff --git a/products/error_tracking/frontend/components/ExceptionCard/Tabs/SessionTab/sessionTabLogic.ts b/products/error_tracking/frontend/components/ExceptionCard/Tabs/SessionTab/sessionTabLogic.ts
index e45bcb0dd9ac..3e035942c4b3 100644
--- a/products/error_tracking/frontend/components/ExceptionCard/Tabs/SessionTab/sessionTabLogic.ts
+++ b/products/error_tracking/frontend/components/ExceptionCard/Tabs/SessionTab/sessionTabLogic.ts
@@ -6,6 +6,7 @@ import {
events,
kea,
key,
+ listeners,
path,
props,
propsChanged,
@@ -22,11 +23,9 @@ import { SessionPlayerData } from '~/types'
export type SessionTabLogicProps = {
sessionId: string
- timestamp: string
+ timestamp?: string
}
-export type TabId = 'recording' | 'timeline'
-
export type TimelineEvent = {
uuid: string
event: string
@@ -54,11 +53,23 @@ export interface sessionTabLogicValues {
recordingProps: SessionRecordingPlayerProps
recordingTimestamp: number | null
sessionId: string
- timestamp: string
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface sessionTabLogicActions {
+ loadRecordingMetaSuccess: (
+ sessionPlayerMetaData: null | import('~/types').SessionRecordingType,
+ payload?:
+ | {
+ value: true
+ }
+ | undefined
+ ) => {
+ payload?: {
+ value: true
+ }
+ sessionPlayerMetaData: null | import('~/types').SessionRecordingType
+ } // sessionRecordingDataCoordinatorLogic
seekToTimestamp: (
timestamp: number,
forcePlay?: boolean | undefined
@@ -86,7 +97,6 @@ export interface sessionTabLogicMeta {
key: KeyType
__keaTypeGenInternalSelectorTypes: {
sessionId: (sessionId: string) => string
- timestamp: (timestamp: string) => string
recordingProps: (sessionId: string) => SessionRecordingPlayerProps
isTimestampOutsideRecording: (
exceptionTimestamp: number | null,
@@ -113,13 +123,15 @@ export const sessionTabLogic = kea<sessionTabLogicType>([
['isNotFound', 'sessionPlayerMetaDataLoading', 'sessionPlayerData'],
],
actions: [
+ sessionRecordingDataCoordinatorLogic(getRecordingProps(sessionId)),
+ ['loadRecordingMetaSuccess'],
sessionRecordingPlayerLogic(getRecordingProps(sessionId)),
['seekToTimestamp', 'setPlay', 'setPause'],
],
})),
propsChanged(({ actions, props }, oldProps) => {
- if (props.timestamp !== oldProps.timestamp) {
+ if (props.timestamp && props.timestamp !== oldProps.timestamp) {
actions.setRecordingTimestamp(dayjs(props.timestamp), 5000)
}
}),
@@ -144,7 +156,6 @@ export const sessionTabLogic = kea<sessionTabLogicType>([
}),
selectors({
sessionId: [(_, p) => [p.sessionId], (sessionId: string) => sessionId],
- timestamp: [(_, p) => [p.timestamp], (timestamp: string) => timestamp],
recordingProps: [
(_, p) => [p.sessionId],
(sessionId: string) => {
@@ -173,9 +184,27 @@ export const sessionTabLogic = kea<sessionTabLogicType>([
},
],
}),
+ listeners(({ actions, values }) => {
+ const playFromSelectedTimestamp = (): void => {
+ if (values.sessionPlayerMetaDataLoading || values.isNotFound) {
+ return
+ }
+ if (values.recordingTimestamp) {
+ actions.seekToTimestamp(values.recordingTimestamp)
+ }
+ actions.setPlay()
+ }
+
+ return {
+ setRecordingTimestamp: playFromSelectedTimestamp,
+ loadRecordingMetaSuccess: playFromSelectedTimestamp,
+ }
+ }),
events(({ props, actions }) => ({
afterMount: () => {
- actions.setRecordingTimestamp(dayjs(props.timestamp), 5000)
+ if (props.timestamp) {
+ actions.setRecordingTimestamp(dayjs(props.timestamp), 5000)
+ }
},
})),
])
diff --git a/products/error_tracking/frontend/components/ExceptionCard/exceptionCardLogic.ts b/products/error_tracking/frontend/components/ExceptionCard/exceptionCardLogic.ts
index cd7a2ec8d656..b9fffe9afaa2 100644
--- a/products/error_tracking/frontend/components/ExceptionCard/exceptionCardLogic.ts
+++ b/products/error_tracking/frontend/components/ExceptionCard/exceptionCardLogic.ts
@@ -4,11 +4,14 @@ import posthog from 'lib/posthog-typed'
export type ExceptionCardLogicProps = {
issueId: string
+ loading: boolean
}
+export type ExceptionCardTab = 'stack_trace' | 'properties' | 'timeline' | 'recording'
+
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface exceptionCardLogicValues {
- currentTab: string
+ currentTab: ExceptionCardTab
expandedFrameRawIds: Set<string>
issueId: string
loading: boolean
@@ -18,8 +21,8 @@ export interface exceptionCardLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface exceptionCardLogicActions {
- setCurrentTab: (tab: string) => {
- tab: string
+ setCurrentTab: (tab: ExceptionCardTab) => {
+ tab: ExceptionCardTab
}
setFrameExpanded: (
rawId: string,
@@ -28,9 +31,6 @@ export interface exceptionCardLogicActions {
expanded: boolean
rawId: string
}
- setLoading: (loading: boolean) => {
- loading: boolean
- }
setPropertyNameFilter: (propertyNameFilter: string) => {
propertyNameFilter: string
}
@@ -44,6 +44,7 @@ export interface exceptionCardLogicMeta {
key: string
__keaTypeGenInternalSelectorTypes: {
issueId: (issueId: string) => string
+ loading: (loading: boolean) => boolean
}
}
@@ -61,9 +62,8 @@ export const exceptionCardLogic = kea<exceptionCardLogicType>([
actions({
setShowJSONProperties: (showJSON: boolean) => ({ showJSON }),
- setLoading: (loading: boolean) => ({ loading }),
setPropertyNameFilter: (propertyNameFilter: string) => ({ propertyNameFilter }),
- setCurrentTab: (tab: string) => ({ tab }),
+ setCurrentTab: (tab: ExceptionCardTab) => ({ tab }),
setFrameExpanded: (rawId: string, expanded: boolean) => ({ rawId, expanded }),
}),
@@ -98,22 +98,17 @@ export const exceptionCardLogic = kea<exceptionCardLogicType>([
setPropertyNameFilter: (_, { propertyNameFilter }) => propertyNameFilter,
},
],
- loading: [
- true,
- {
- setLoading: (_, { loading }: { loading: boolean }) => loading,
- },
- ],
currentTab: [
- 'stack_trace',
+ 'stack_trace' as ExceptionCardTab,
{
- setCurrentTab: (_, { tab }: { tab: string }) => tab,
+ setCurrentTab: (_, { tab }) => tab,
},
],
}),
selectors({
issueId: [(_, p) => [p.issueId], (issueId: string) => issueId],
+ loading: [(_, p) => [p.loading], (loading: boolean) => loading],
}),
listeners(({ props }) => ({