: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(desktop): preserve comments in task deep links (#83513)
Shy Alterbe0cca1cdfa2
diff --git a/frontend/src/scenes/code-canvas/CodeTaskLink.test.ts b/frontend/src/scenes/code-canvas/CodeTaskLink.test.tsnew file mode 100644index 000000000000..3a1b047a9193--- /dev/null+++ b/frontend/src/scenes/code-canvas/CodeTaskLink.test.ts@@ -0,0 +1,38 @@+import * as kea from 'kea'+import * as React from 'react'++import { CodeTaskLink, taskDeepLink } from './CodeTaskLink'++jest.mock('react', () => ({+ ...jest.requireActual('react'),+ useEffect: jest.fn(),+}))++describe('CodeTaskLink', () => {+ afterEach(() => {+ jest.restoreAllMocks()+ jest.clearAllMocks()+ })++ it('forwards the comment target from the browser URL to PostHog Desktop', () => {+ expect(+ taskDeepLink('task/1', {+ comment: 'comment/1',+ scope: 'task_artifact',+ item: 'artifact/1',+ })+ ).toBe('posthog-code://task/task%2F1?comment=comment%2F1&scope=task_artifact&item=artifact%2F1')+ })++ it('reads the comment target from the active URL when rendering the bridge', () => {+ jest.spyOn(kea, 'useValues').mockReturnValue({+ searchParams: { comment: 'comment-1' },+ } as never)++ CodeTaskLink({ taskId: 'task-1' })++ expect(React.useEffect).toHaveBeenCalledWith(expect.any(Function), [+ 'posthog-code://task/task-1?comment=comment-1',+ ])+ })+})diff --git a/frontend/src/scenes/code-canvas/CodeTaskLink.tsx b/frontend/src/scenes/code-canvas/CodeTaskLink.tsxindex f447f2073244..57ee32b1cf39 100644--- a/frontend/src/scenes/code-canvas/CodeTaskLink.tsx+++ b/frontend/src/scenes/code-canvas/CodeTaskLink.tsx@@ -1,3 +1,5 @@+import { useValues } from 'kea'+import { router } from 'kea-router'import { useEffect } from 'react'import { IconLaptop } from '@posthog/icons'@@ -10,38 +12,33 @@ import { DESKTOP_SCHEME } from './desktopScheme'export interface CodeTaskLinkProps {taskId: string- commentId?: string- commentScope?: string- commentItemId?: string}export const scene: SceneExport<CodeTaskLinkProps> = {component: CodeTaskLink,- paramsToProps: ({ params: { taskId }, searchParams }) => ({+ paramsToProps: ({ params: { taskId } }) => ({taskId: taskId ?? '',- commentId: searchParams.comment || undefined,- commentScope: searchParams.scope || undefined,- commentItemId: searchParams.item || undefined,}),}-function taskDeepLink({ taskId, commentId, commentScope, commentItemId }: CodeTaskLinkProps): string {+export function taskDeepLink(taskId: string, searchParams: Record<string, unknown>): string {const params = new URLSearchParams()- if (commentId) {- params.set('comment', commentId)+ if (typeof searchParams.comment === 'string') {+ params.set('comment', searchParams.comment)}- if (commentScope) {- params.set('scope', commentScope)+ if (typeof searchParams.scope === 'string') {+ params.set('scope', searchParams.scope)}- if (commentItemId) {- params.set('item', commentItemId)+ if (typeof searchParams.item === 'string') {+ params.set('item', searchParams.item)}const query = params.toString()return `${DESKTOP_SCHEME}://task/${encodeURIComponent(taskId)}${query ? `?${query}` : ''}`}-export function CodeTaskLink(props: CodeTaskLinkProps): JSX.Element {- const deepLink = props.taskId ? taskDeepLink(props) : null+export function CodeTaskLink({ taskId }: CodeTaskLinkProps): JSX.Element {+ const { searchParams } = useValues(router)+ const deepLink = taskId ? taskDeepLink(taskId, searchParams) : nulluseEffect(() => {if (deepLink) {