: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(conversations): stop support checkbox clearing itself on click (#63213)
Paul D'Ambraf83ca46db5b8
diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 3f6d4905d18a..edcb7cfb6d0c 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -2448,6 +2448,19 @@ importers:ts-pattern:specifier: 'catalog:'version: 4.3.0+ devDependencies:+ '@testing-library/jest-dom':+ specifier: ^5.17.0+ version: 5.17.0+ '@testing-library/react':+ specifier: ^14.3.1+ version: 14.3.1(@types/[email protected])([email protected]([email protected]))([email protected])+ '@testing-library/user-event':+ specifier: ^14.6.1+ version: 14.6.1(@testing-library/[email protected])+ jest:+ specifier: ^29.7.0+ version: 29.7.0(@types/[email protected])([email protected](@swc/[email protected])(@types/[email protected])([email protected]))products/core_events: {}diff --git a/products/conversations/frontend/scenes/tickets/SupportTicketsScene.test.tsx b/products/conversations/frontend/scenes/tickets/SupportTicketsScene.test.tsxnew file mode 100644index 000000000000..a9728858e5c8--- /dev/null+++ b/products/conversations/frontend/scenes/tickets/SupportTicketsScene.test.tsx@@ -0,0 +1,99 @@+import '@testing-library/jest-dom'++import { act, cleanup, render, screen, waitFor } from '@testing-library/react'+import userEvent from '@testing-library/user-event'+import { Provider } from 'kea'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'++import { Ticket } from '../../types'+import { SupportTicketsTable } from './SupportTicketsScene'+import { supportTicketsSceneLogic } from './supportTicketsSceneLogic'++const TICKET: Ticket = {+ id: 'ticket-1',+ ticket_number: 1,+ distinct_id: 'distinct-1',+ status: 'open',+ channel_source: 'email',+ anonymous_traits: {},+ ai_resolved: false,+ created_at: '2026-06-12T00:00:00Z',+ updated_at: '2026-06-12T00:00:00Z',+ message_count: 1,+ last_message_at: '2026-06-12T00:00:00Z',+ last_message_text: 'Hello',+ unread_team_count: 0,+ unread_customer_count: 0,+}++describe('SupportTicketsTable selection', () => {+ let logic: ReturnType<typeof supportTicketsSceneLogic.build>++ beforeEach(() => {+ useMocks({+ get: {+ '/api/projects/:team_id/conversations/tickets/': () => [200, { results: [TICKET], count: 1 }],+ '/api/organizations/:organization_id/members/': () => [200, { results: [] }],+ },+ })+ initKeaTests()+ logic = supportTicketsSceneLogic()+ logic.mount()+ // Seed a ticket directly so we don't depend on the debounced loadTickets request.+ act(() => {+ logic.actions.setTickets([TICKET])+ })+ })++ afterEach(() => {+ logic.unmount()+ cleanup()+ })++ function getRowCheckbox(): HTMLInputElement {+ // Two checkboxes render: [0] the header "select all on page", [1] the single row.+ const checkboxes = screen.getAllByRole('checkbox')+ expect(checkboxes).toHaveLength(2)+ return checkboxes[1] as HTMLInputElement+ }++ // Regression: the hook selection (selectedKeys) and kea (selectedTicketIds) were synced by+ // two effects, and on the first click the "clear when kea is empty" effect fired before the+ // push effect had propagated — instantly wiping the selection. The checkbox never stuck.+ it('keeps a row checked after clicking and pushes the id into kea', async () => {+ render(+ <Provider>+ <SupportTicketsTable />+ </Provider>+ )++ const rowCheckbox = getRowCheckbox()+ expect(rowCheckbox).not.toBeChecked()++ await userEvent.click(rowCheckbox)++ await waitFor(() => expect(getRowCheckbox()).toBeChecked())+ expect(logic.values.selectedTicketIds).toEqual([TICKET.id])+ })++ it('clears the checkbox when the kea selection is reset externally', async () => {+ render(+ <Provider>+ <SupportTicketsTable />+ </Provider>+ )++ await userEvent.click(getRowCheckbox())+ await waitFor(() => expect(getRowCheckbox()).toBeChecked())++ // A bulk update / page reload resets the kea selection — the hook should follow.+ act(() => {+ logic.actions.clearSelectedTickets()+ })++ await waitFor(() => expect(getRowCheckbox()).not.toBeChecked())+ expect(logic.values.selectedTicketIds).toEqual([])+ })+})diff --git a/products/conversations/frontend/scenes/tickets/SupportTicketsScene.tsx b/products/conversations/frontend/scenes/tickets/SupportTicketsScene.tsxindex 53d362c730ce..2dcf86bc4707 100644--- a/products/conversations/frontend/scenes/tickets/SupportTicketsScene.tsx+++ b/products/conversations/frontend/scenes/tickets/SupportTicketsScene.tsx@@ -1,7 +1,7 @@import clsx from 'clsx'import { useActions, useMountedLogic, useValues } from 'kea'import { router } from 'kea-router'-import { useEffect, useMemo } from 'react'+import { useEffect, useMemo, useRef } from 'react'import { IconChevronDown, IconClock, IconRefresh, IconX } from '@posthog/icons'import {@@ -276,9 +276,16 @@ export function SupportTicketsTable({ embedded = false }: SupportTicketsTableProsetSelectedTicketIds(selectedKeys)}, [selectedKeys, setSelectedTicketIds])- // Clear hook selection when kea resets (e.g. after bulk update or page reload)+ // Clear hook selection only when kea's selection is reset *externally* (e.g. after a bulk+ // update or page reload). We detect that as a non-empty -> empty transition. Reacting to+ // `selectedTicketIds.length === 0` alone would also fire during the brief window right after+ // the first selection, before the effect above has pushed `selectedKeys` into kea — which+ // would immediately wipe the selection the user just made.+ const prevSelectedTicketIdCount = useRef(selectedTicketIds.length)useEffect(() => {- if (selectedTicketIds.length === 0 && selectedKeys.length > 0) {+ const wasSelected = prevSelectedTicketIdCount.current > 0+ prevSelectedTicketIdCount.current = selectedTicketIds.length+ if (wasSelected && selectedTicketIds.length === 0 && selectedKeys.length > 0) {clearSelection()}}, [selectedTicketIds, selectedKeys, clearSelection])diff --git a/products/conversations/package.json b/products/conversations/package.jsonindex 092a4d0b8d05..dd2f484e5306 100644--- a/products/conversations/package.json+++ b/products/conversations/package.json@@ -11,9 +11,18 @@"posthog-js": "catalog:","ts-pattern": "catalog:"},+ "devDependencies": {+ "@testing-library/jest-dom": "^5.17.0",+ "@testing-library/react": "^14.3.1",+ "@testing-library/user-event": "^14.6.1",+ "jest": "^29.7.0"+ },"peerDependencies": {"@posthog/icons": "*","@posthog/lemon-ui": "*",+ "@testing-library/jest-dom": "*",+ "@testing-library/react": "*",+ "@testing-library/user-event": "*","@tiptap/core": "*","@tiptap/extension-code-block-lowlight": "*","@tiptap/extension-document": "*",@@ -26,6 +35,7 @@"@types/react": "*","@types/react-dom": "*","clsx": "*",+ "jest": "*","lowlight": "*","react": "*","react-dom": "*"