: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(replay): give the sidebar tab its own URL param (#76376)
Marcel Poelkerca5571c39606
diff --git a/frontend/src/scenes/session-recordings/player/sidebar/playerSidebarLogic.test.ts b/frontend/src/scenes/session-recordings/player/sidebar/playerSidebarLogic.test.tsindex 99323b76e138..232b4b321e89 100644--- a/frontend/src/scenes/session-recordings/player/sidebar/playerSidebarLogic.test.ts+++ b/frontend/src/scenes/session-recordings/player/sidebar/playerSidebarLogic.test.ts@@ -33,7 +33,7 @@ describe('playerSidebarLogic', () => {}).toMatchValues({ activeTab: SessionRecordingSidebarTab.NETWORK_WATERFALL })})- it('records a tab from the URL as the pick, even when a host default already matches it', async () => {+ it("still reads a bare tab from an older link, as the viewer's pick", async () => {logic.actions.setDefaultTab(SessionRecordingSidebarTab.OVERVIEW)router.actions.push('/replay', {sessionRecordingId: 'abc',@@ -48,12 +48,48 @@ describe('playerSidebarLogic', () => {}).toMatchValues({ activeTab: SessionRecordingSidebarTab.OVERVIEW })})+ it('honors a tab from the URL when no recording id is in the URL', async () => {+ // On /replay/home the first recording autoplays without its id ever reaching the URL, so a+ // refresh has to restore the tab without one to key off. Remounting with the tab already in+ // the URL is what that refresh looks like.+ logic.unmount()+ router.actions.push('/replay/home', { sidebarTab: SessionRecordingSidebarTab.NETWORK_WATERFALL })+ logic = playerSidebarLogic()+ logic.mount()++ await expectLogic(logic).toMatchValues({ activeTab: SessionRecordingSidebarTab.NETWORK_WATERFALL })+ })++ it('leaves a bare tab alone when another scene owns it', async () => {+ // Two sidebar tab values are also tab values elsewhere ('overview' on a group page,+ // 'sessions' in activity), and this logic matches on '*', so it sees those URLs too.+ router.actions.push('/groups/0/abc', { tab: SessionRecordingSidebarTab.OVERVIEW })++ await expectLogic(logic).toMatchValues({+ selectedTab: null,+ activeTab: SessionRecordingSidebarTab.INSPECTOR,+ })+ })++ it("leaves a host scene's own tab untouched when the viewer picks a sidebar tab", () => {+ // The experiment view keeps its active tab in `tab` and clamps a value it doesn't know back+ // to its default, so writing the sidebar's pick there drops the viewer out of the recording.+ router.actions.push('/experiments/123', { tab: 'recordings' })++ logic.actions.setTab(SessionRecordingSidebarTab.NETWORK_WATERFALL)++ expect(router.values.searchParams).toEqual({+ tab: 'recordings',+ sidebarTab: SessionRecordingSidebarTab.NETWORK_WATERFALL,+ })+ })+it('keeps the host default out of the URL', () => {logic.actions.setDefaultTab(SessionRecordingSidebarTab.OVERVIEW)- expect(router.values.searchParams).not.toHaveProperty('tab')+ expect(router.values.searchParams).not.toHaveProperty('sidebarTab')// The viewer's own pick is theirs to share, so that one does belong in the URL.logic.actions.setTab(SessionRecordingSidebarTab.OVERVIEW)- expect(router.values.searchParams).toHaveProperty('tab', SessionRecordingSidebarTab.OVERVIEW)+ expect(router.values.searchParams).toHaveProperty('sidebarTab', SessionRecordingSidebarTab.OVERVIEW)})})diff --git a/frontend/src/scenes/session-recordings/player/sidebar/playerSidebarLogic.ts b/frontend/src/scenes/session-recordings/player/sidebar/playerSidebarLogic.tsindex 2103bac63de6..8f0a8bf62307 100644--- a/frontend/src/scenes/session-recordings/player/sidebar/playerSidebarLogic.ts+++ b/frontend/src/scenes/session-recordings/player/sidebar/playerSidebarLogic.ts@@ -3,6 +3,11 @@ import { actionToUrl, router, urlToAction } from 'kea-router'import { SessionRecordingSidebarTab } from '~/types'+const asSidebarTab = (value: unknown): SessionRecordingSidebarTab | null =>+ Object.values(SessionRecordingSidebarTab).includes(value as SessionRecordingSidebarTab)+ ? (value as SessionRecordingSidebarTab)+ : null+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface playerSidebarLogicValues {activeTab: SessionRecordingSidebarTab@@ -76,7 +81,7 @@ export const playerSidebarLogic = kea<playerSidebarLogicType>([currentLocation.pathname,{...currentLocation.searchParams,- tab,+ sidebarTab: tab,},currentLocation.hashParams,]@@ -85,20 +90,28 @@ export const playerSidebarLogic = kea<playerSidebarLogicType>([urlToAction(({ actions, values }) => ({'*': (_, searchParams, hashParams) => {+ // This matcher is `'*'`, so the sidebar sees every route, including the scenes that+ // keep their own `tab` — the experiment view, a group page. Holding its tab under a+ // name no other scene claims is what makes it safe to read here and safe to write+ // there: a host that reads `tab` never sees a value the sidebar put in it.+ const urlTab = asSidebarTab(searchParams.sidebarTab) ?? asSidebarTab(hashParams.sidebarTab)++ // Older links carry the tab as a bare `tab`. Reading one has to prove a recording is on+ // screen first, since two of this enum's values ('overview', 'sessions') are also tab+ // values on scenes this matcher sees.const isShowingRecording =Object.keys(searchParams).includes('sessionRecordingId') ||Object.keys(hashParams).includes('sessionRecordingId')- const urlTab = Object.values(SessionRecordingSidebarTab).includes(searchParams.tab)- ? (searchParams.tab as SessionRecordingSidebarTab)- : Object.values(SessionRecordingSidebarTab).includes(hashParams.tab)- ? (hashParams.tab as SessionRecordingSidebarTab)- : null+ const legacyTab = isShowingRecording+ ? (asSidebarTab(searchParams.tab) ?? asSidebarTab(hashParams.tab))+ : null// Compared against the viewer's pick rather than the active tab: a tab in the URL is an// explicit choice, and checking the active tab would skip recording it whenever a host// default happened to match — the choice would then evaporate once that host went away.- if (isShowingRecording && urlTab && urlTab !== values.selectedTab) {- actions.setTab(urlTab)+ const nextTab = urlTab ?? legacyTab+ if (nextTab && nextTab !== values.selectedTab) {+ actions.setTab(nextTab)}},})),