: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): refetch tickets when opening the my-tickets page (#81142)
Christian Rafferty1d5446cf7be8
diff --git a/products/conversations/frontend/scenes/myTickets/MyTicketsScene.tsx b/products/conversations/frontend/scenes/myTickets/MyTicketsScene.tsxindex 758ca1f8fc29..b3e4cdb3dfa9 100644--- a/products/conversations/frontend/scenes/myTickets/MyTicketsScene.tsx+++ b/products/conversations/frontend/scenes/myTickets/MyTicketsScene.tsx@@ -13,10 +13,14 @@ import { RestoreTickets } from '../../components/SidePanel/RestoreTickets'import { sidepanelTicketsLogic } from '../../components/SidePanel/sidepanelTicketsLogic'import { Ticket } from '../../components/SidePanel/Ticket'import { TicketsList } from '../../components/SidePanel/TicketsList'+import { myTicketsSceneLogic } from './myTicketsSceneLogic'+// myTicketsSceneLogic rather than sidepanelTicketsLogic directly: the tickets logic never unmounts+// (the side panel tab icon keeps it alive), so only a scene-scoped logic gets a fresh mount, and+// with it a ticket refetch, on each navigation hereexport const scene: SceneExport = {component: MyTicketsScene,- logic: sidepanelTicketsLogic,+ logic: myTicketsSceneLogic,}// Sized against the viewport so the thread fills the page without the scene itself scrollingdiff --git a/products/conversations/frontend/scenes/myTickets/myTicketsSceneLogic.test.ts b/products/conversations/frontend/scenes/myTickets/myTicketsSceneLogic.test.tsnew file mode 100644index 000000000000..fe27f807da23--- /dev/null+++ b/products/conversations/frontend/scenes/myTickets/myTicketsSceneLogic.test.ts@@ -0,0 +1,43 @@+import { expectLogic } from 'kea-test-utils'+import posthog from 'posthog-js'++import { initKeaTests } from '~/test/init'++import { sidepanelTicketsLogic } from '../../components/SidePanel/sidepanelTicketsLogic'+import { myTicketsSceneLogic } from './myTicketsSceneLogic'++describe('myTicketsSceneLogic', () => {+ beforeEach(() => {+ initKeaTests()+ ;(posthog as any).conversations = {+ isAvailable: () => true,+ getTickets: jest.fn().mockResolvedValue({ results: [] }),+ }+ })++ afterEach(() => {+ delete (posthog as any).conversations+ })++ // The tickets logic stays mounted for the whole session via the side panel tab icon, so its own+ // boot-time load never re-runs. Without the scene-mount refetch, navigating to /my-tickets shows+ // whatever the boot-time load returned (often nothing) until a full page reload.+ it('refetches tickets when the scene mounts while the tickets logic is already mounted', async () => {+ const ticketsLogic = sidepanelTicketsLogic.build()+ ticketsLogic.mount()+ await expectLogic(ticketsLogic).toFinishAllListeners()++ const getTickets = (posthog as any).conversations.getTickets as jest.Mock+ const callsAtBoot = getTickets.mock.calls.length+ expect(callsAtBoot).toBeGreaterThan(0)++ const sceneLogic = myTicketsSceneLogic.build()+ sceneLogic.mount()+ await expectLogic(ticketsLogic).toFinishAllListeners()++ expect(getTickets.mock.calls.length).toBe(callsAtBoot + 1)++ sceneLogic.unmount()+ ticketsLogic.unmount()+ })+})diff --git a/products/conversations/frontend/scenes/myTickets/myTicketsSceneLogic.ts b/products/conversations/frontend/scenes/myTickets/myTicketsSceneLogic.tsnew file mode 100644index 000000000000..7b9c14a48ef0--- /dev/null+++ b/products/conversations/frontend/scenes/myTickets/myTicketsSceneLogic.ts@@ -0,0 +1,26 @@+import { MakeLogicType, afterMount, connect, kea, path } from 'kea'++import { sidepanelTicketsLogic } from '../../components/SidePanel/sidepanelTicketsLogic'++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface myTicketsSceneLogicActions {+ loadTickets: () => {+ value: true+ } // sidepanelTicketsLogic+}++export type myTicketsSceneLogicType = MakeLogicType<{}, myTicketsSceneLogicActions>++// sidepanelTicketsLogic stays mounted for the whole session (the side panel tab icon reads its+// unread count), so its own initial load runs once at app boot and never again. This scene-scoped+// logic exists to refetch on every navigation to the tickets scene, the same way the side panel+// refetches each time it opens.+export const myTicketsSceneLogic = kea<myTicketsSceneLogicType>([+ path(['products', 'conversations', 'frontend', 'scenes', 'myTickets', 'myTicketsSceneLogic']),+ connect(() => ({+ actions: [sidepanelTicketsLogic, ['loadTickets']],+ })),+ afterMount(({ actions }) => {+ actions.loadTickets()+ }),+])