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(error-tracking): fall back to default sort for invalid orderBy (#72347)

Aleksander Błaszkiewiczdddf29ced166
diff --git a/products/error_tracking/frontend/components/IssueFilteringTool.tsx b/products/error_tracking/frontend/components/IssueFilteringTool.tsx
index 9d4689dcd13a..ec82c06248d9 100644
--- a/products/error_tracking/frontend/components/IssueFilteringTool.tsx
+++ b/products/error_tracking/frontend/components/IssueFilteringTool.tsx
@@ -13,7 +13,7 @@ import { useAttachedContext } from 'products/posthog_ai/frontend/api/logics'
import { errorTrackingSceneLogic } from '../scenes/ErrorTrackingScene/errorTrackingSceneLogic'
import { TAXONOMIC_FILTER_LOGIC_KEY, TAXONOMIC_GROUP_TYPES } from './IssueFilters/consts'
import { issueFiltersLogic } from './IssueFilters/issueFiltersLogic'
-import { issueQueryOptionsLogic } from './IssueQueryOptions/issueQueryOptionsLogic'
+import { isValidOrderBy, issueQueryOptionsLogic } from './IssueQueryOptions/issueQueryOptionsLogic'
function updateFilterGroup(
removedFilterIndexes: number[] | undefined,
@@ -80,7 +80,7 @@ export function ErrorTrackingIssueFilteringTool(): JSX.Element {
useAttachedContext([{ type: 'error_tracking_query', value: JSON.stringify(query), label: 'Current filters' }])
const callback = (update: ErrorTrackingIssueFilteringToolOutput): void => {
- if (update.orderBy) {
+ if (update.orderBy && isValidOrderBy(update.orderBy)) {
setOrderBy(update.orderBy)
}
if (update.orderDirection) {
diff --git a/products/error_tracking/frontend/components/IssueQueryOptions/issueQueryOptionsLogic.ts b/products/error_tracking/frontend/components/IssueQueryOptions/issueQueryOptionsLogic.ts
index 60c5e33028a6..9271e20fd4aa 100644
--- a/products/error_tracking/frontend/components/IssueQueryOptions/issueQueryOptionsLogic.ts
+++ b/products/error_tracking/frontend/components/IssueQueryOptions/issueQueryOptionsLogic.ts
@@ -1,5 +1,5 @@
import { deepEqual as equal } from 'fast-equals'
-import { MakeLogicType, actions, kea, key, listeners, path, props, reducers } from 'kea'
+import { MakeLogicType, actions, afterMount, kea, key, listeners, path, props, reducers } from 'kea'
import { actionToUrl, router, urlToAction } from 'kea-router'
import posthog from 'posthog-js'
@@ -26,6 +26,14 @@ export const ORDER_BY_OPTIONS: Record<ErrorTrackingQueryOrderBy, string> = {
sessions: 'Sessions',
}
const DEFAULT_ORDER_BY: ErrorTrackingQueryOrderBy = 'last_seen'
+
+// A persisted (localStorage) or tool-provided orderBy can hold a value that's no longer a
+// valid sort field — e.g. an option that was renamed or removed. Passing it through to the
+// query fails the whole page, so anything unrecognized falls back to the default.
+export function isValidOrderBy(orderBy: unknown): orderBy is ErrorTrackingQueryOrderBy {
+ return typeof orderBy === 'string' && Object.hasOwn(ORDER_BY_OPTIONS, orderBy)
+}
+
const DEFAULT_ORDER_DIRECTION = 'DESC'
const DEFAULT_ASSIGNEE = null
const DEFAULT_STATUS = 'active'
@@ -87,7 +95,7 @@ export const issueQueryOptionsLogic = kea<issueQueryOptionsLogicType>([
DEFAULT_ORDER_BY as ErrorTrackingQueryOrderBy,
{ persist: true },
{
- setOrderBy: (_, { orderBy }) => orderBy,
+ setOrderBy: (_, { orderBy }) => (isValidOrderBy(orderBy) ? orderBy : DEFAULT_ORDER_BY),
},
],
orderDirection: [
@@ -157,7 +165,7 @@ export const issueQueryOptionsLogic = kea<issueQueryOptionsLogicType>([
urlToAction(({ actions, values }) => {
const urlToAction = (_: any, params: Params): void => {
if (params.orderBy && !equal(params.orderBy, values.orderBy)) {
- if (params.orderBy in ORDER_BY_OPTIONS) {
+ if (isValidOrderBy(params.orderBy)) {
actions.setOrderBy(params.orderBy)
}
}
@@ -175,4 +183,12 @@ export const issueQueryOptionsLogic = kea<issueQueryOptionsLogicType>([
'*': urlToAction,
}
}),
+
+ afterMount(({ actions, values }) => {
+ // The persisted orderBy is loaded straight into state (bypassing the reducer), so an
+ // invalid stored value would otherwise reach the query and break the page. Reset it.
+ if (!isValidOrderBy(values.orderBy)) {
+ actions.setOrderBy(DEFAULT_ORDER_BY)
+ }
+ }),
])