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.

feat(desktop): offer a browser link on desktop share link pages (#120341)

Vojta Bartoše14e4988220e
diff --git a/frontend/src/scenes/code-canvas/CodeCanvasLink.test.tsx b/frontend/src/scenes/code-canvas/CodeCanvasLink.test.tsx
new file mode 100644
index 000000000000..f691d5ca1843
--- /dev/null
+++ b/frontend/src/scenes/code-canvas/CodeCanvasLink.test.tsx
@@ -0,0 +1,61 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, render, screen } from '@testing-library/react'
+import { Provider } from 'kea'
+import { router } from 'kea-router'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+
+import { initKeaTests } from '~/test/init'
+
+import { CodeCanvasLink } from './CodeCanvasLink'
+
+describe('CodeCanvasLink', () => {
+ beforeEach(() => {
+ // jsdom refuses a real navigation, so stand in a location whose href we can read back.
+ Object.defineProperty(window, 'location', {
+ configurable: true,
+ value: { ...window.location, href: '' },
+ })
+ initKeaTests()
+ })
+
+ afterEach(() => {
+ cleanup()
+ })
+
+ it.each([
+ ['an unscoped link, in the current project', '/code/canvas/channel-1/canvas-1', /\/canvases\/canvas-1$/],
+ [
+ 'a project-scoped link, in that project',
+ '/project/7/code/canvas/channel-1/canvas-1',
+ /\/project\/7\/canvases\/canvas-1$/,
+ ],
+ ])('links to the canvas in the browser for %s', (_, path, expectedHref) => {
+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.TODAY_RAIL_NAV]: true })
+ router.actions.push(path)
+ render(
+ <Provider>
+ <CodeCanvasLink channelId="channel-1" dashboardId="canvas-1" />
+ </Provider>
+ )
+
+ expect(window.location.href).toBe('posthog-code://canvas/channel-1/canvas-1')
+ expect(screen.getByText('Open in browser').closest('a')).toHaveAttribute(
+ 'href',
+ expect.stringMatching(expectedHref)
+ )
+ })
+
+ it('hides the browser link when the web canvas would show not found', () => {
+ featureFlagLogic.actions.setFeatureFlags([], {})
+ render(
+ <Provider>
+ <CodeCanvasLink channelId="channel-1" dashboardId="canvas-1" />
+ </Provider>
+ )
+
+ expect(screen.queryByText('Open in browser')).not.toBeInTheDocument()
+ })
+})
diff --git a/frontend/src/scenes/code-canvas/CodeCanvasLink.tsx b/frontend/src/scenes/code-canvas/CodeCanvasLink.tsx
index 6bfd980c4492..8a2ba7fb3d7c 100644
--- a/frontend/src/scenes/code-canvas/CodeCanvasLink.tsx
+++ b/frontend/src/scenes/code-canvas/CodeCanvasLink.tsx
@@ -1,10 +1,15 @@
+import { useValues } from 'kea'
+import { router } from 'kea-router'
import { useEffect } from 'react'
import { BridgePage } from 'lib/components/BridgePage/BridgePage'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { SceneExport } from 'scenes/sceneTypes'
+import { urls } from 'scenes/urls'
import { DesktopBridgeBody } from './DesktopBridgeBody'
import { DESKTOP_SCHEME } from './desktopScheme'
+import { webPath } from './webPath'
export interface CodeCanvasLinkProps {
channelId: string
@@ -28,13 +33,17 @@ function canvasDeepLink(channelId: string, dashboardId: string): string {
* (`/code/canvas/<channelId>/<dashboardId>`). On mount it deep-links into the desktop
* app via the `posthog-code(-dev)://` custom scheme; for visitors without the app it
* shows an explanation, a manual "open" button (in case the browser blocks the
- * auto-redirect), and a download link. The canvas itself only exists in the desktop
- * app, so nothing is rendered here beyond this interstitial.
+ * auto-redirect), and a download link. Visitors who can open canvases on the web also
+ * get a link to the canvas in the browser.
*/
export function CodeCanvasLink({ channelId, dashboardId }: CodeCanvasLinkProps): JSX.Element {
// Null when a param is missing (a partial URL or params not yet resolved) —
// firing with an empty id would send a malformed `<scheme>://canvas//`.
const deepLink = channelId && dashboardId ? canvasDeepLink(channelId, dashboardId) : null
+ // The web canvas scene shows "Not found" without this flag, so only offer it to visitors who have it.
+ const webCanvasEnabled = useFeatureFlag('TODAY_RAIL_NAV')
+ const { location } = useValues(router)
+ const webUrl = webCanvasEnabled && dashboardId ? webPath(location.pathname, urls.canvasDetail(dashboardId)) : null
useEffect(() => {
if (deepLink) {
@@ -44,7 +53,7 @@ export function CodeCanvasLink({ channelId, dashboardId }: CodeCanvasLinkProps):
return (
<BridgePage view="code-canvas-link">
- <DesktopBridgeBody subject="This canvas" deepLink={deepLink} />
+ <DesktopBridgeBody subject="This canvas" deepLink={deepLink} webUrl={webUrl} />
</BridgePage>
)
}
diff --git a/frontend/src/scenes/code-canvas/CodeChannelLink.tsx b/frontend/src/scenes/code-canvas/CodeChannelLink.tsx
index 4cbe6f1849f1..e4f9ad0ccaee 100644
--- a/frontend/src/scenes/code-canvas/CodeChannelLink.tsx
+++ b/frontend/src/scenes/code-canvas/CodeChannelLink.tsx
@@ -1,10 +1,15 @@
+import { useValues } from 'kea'
+import { router } from 'kea-router'
import { useEffect } from 'react'
import { BridgePage } from 'lib/components/BridgePage/BridgePage'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { SceneExport } from 'scenes/sceneTypes'
+import { urls } from 'scenes/urls'
import { DesktopBridgeBody } from './DesktopBridgeBody'
import { DESKTOP_SCHEME } from './desktopScheme'
+import { webPath } from './webPath'
export interface CodeChannelLinkProps {
channelId: string
@@ -29,14 +34,19 @@ function channelDeepLink(channelId: string, taskId?: string): string {
* (`/code/channel/<channelId>` and `/code/channel/<channelId>/tasks/<taskId>`). On mount it
* deep-links into the desktop app via the `posthog-code(-dev)://` custom scheme; for visitors
* without the app it shows an explanation, a manual "open" button (in case the browser blocks
- * the auto-redirect), and a download link. Channels and their threads only exist in the desktop
- * app, so nothing is rendered here beyond this interstitial.
+ * the auto-redirect), and a download link. Visitors who can open spaces on the web also get a
+ * link to the channel's space in the browser. Thread links skip it, because the web space has no thread view.
*/
export function CodeChannelLink({ channelId, taskId }: CodeChannelLinkProps): JSX.Element {
// Null when the channel id is missing (a partial URL or params not yet resolved), since
// firing with an empty id would send a malformed `<scheme>://channel/`.
const deepLink = channelId ? channelDeepLink(channelId, taskId) : null
const target = taskId ? 'thread' : 'channel'
+ // The web space scene shows "Not found" without this flag, so only offer it to visitors who have it.
+ const webSpacesEnabled = useFeatureFlag('TODAY_RAIL_NAV')
+ const { location } = useValues(router)
+ const webUrl =
+ webSpacesEnabled && channelId && !taskId ? webPath(location.pathname, urls.taskSpace(channelId)) : null
useEffect(() => {
if (deepLink) {
@@ -46,7 +56,7 @@ export function CodeChannelLink({ channelId, taskId }: CodeChannelLinkProps): JS
return (
<BridgePage view="code-channel-link">
- <DesktopBridgeBody subject={`This ${target}`} deepLink={deepLink} />
+ <DesktopBridgeBody subject={`This ${target}`} deepLink={deepLink} webUrl={webUrl} />
</BridgePage>
)
}
diff --git a/frontend/src/scenes/code-canvas/DesktopBridgeBody.tsx b/frontend/src/scenes/code-canvas/DesktopBridgeBody.tsx
index cc679f1583cc..95d3830f12cc 100644
--- a/frontend/src/scenes/code-canvas/DesktopBridgeBody.tsx
+++ b/frontend/src/scenes/code-canvas/DesktopBridgeBody.tsx
@@ -1,43 +1,51 @@
import { IconLaptop } from '@posthog/icons'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
+import { Link } from 'lib/lemon-ui/Link'
+
+import { desktopBridgeDescription, openInDesktop } from './desktopBridge'
+import { QuillDesktopBridgeBody } from './QuillDesktopBridgeBody'
export interface DesktopBridgeBodyProps {
/** What the interstitial is opening, e.g. "This canvas", "This task". Starts the explanatory sentence. */
subject: string
/** The `posthog-code(-dev)://…` URL to open, or null while its id isn't resolved yet. */
deepLink: string | null
+ /** The same item in the web app, for visitors who would rather not use the desktop app. Null when it has no web view. */
+ webUrl?: string | null
}
/**
* Shared body for the desktop-app bridge scenes (canvas/channel/task/loop links): an explanation,
* a manual "open" button (in case the browser blocks the auto-redirect the scene fires on mount),
- * and a download link for visitors without the app installed.
+ * an "open in browser" button when the item also has a web view, and a download link for visitors without the app.
*/
-export function DesktopBridgeBody({ subject, deepLink }: DesktopBridgeBodyProps): JSX.Element {
+export function DesktopBridgeBody({ subject, deepLink, webUrl }: DesktopBridgeBodyProps): JSX.Element {
+ const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')
+ if (todayRailNav) {
+ return <QuillDesktopBridgeBody subject={subject} deepLink={deepLink} webUrl={webUrl} />
+ }
return (
<div className="flex flex-col items-center gap-4 text-center max-w-lg mx-auto">
<IconLaptop className="text-5xl shrink-0" />
<h2 className="text-xl font-semibold m-0">Opening in PostHog Desktop…</h2>
- <p className="text-muted mb-0">
- {subject} lives in the PostHog Desktop app. If it's installed, it should open automatically. If it
- didn't, use the button below, or download the app.
- </p>
- <div className="flex flex-col items-center gap-2">
+ <p className="text-muted mb-0">{desktopBridgeDescription(subject, !!webUrl)}</p>
+ <div className="flex flex-wrap justify-center gap-2">
{deepLink && (
- <LemonButton
- type="primary"
- onClick={() => {
- window.location.href = deepLink
- }}
- >
- Open in PostHog Desktop
+ <LemonButton type="primary" onClick={() => openInDesktop(deepLink)}>
+ Open in desktop app
+ </LemonButton>
+ )}
+ {webUrl && (
+ <LemonButton type="secondary" to={webUrl} data-attr="desktop-bridge-open-in-browser">
+ Open in browser
</LemonButton>
)}
- <LemonButton type="secondary" to="https://posthog.com/desktop" targetBlank>
- Download PostHog Desktop
- </LemonButton>
</div>
+ <Link to="https://posthog.com/desktop" target="_blank">
+ Download PostHog Desktop
+ </Link>
</div>
)
}
diff --git a/frontend/src/scenes/code-canvas/QuillDesktopBridgeBody.tsx b/frontend/src/scenes/code-canvas/QuillDesktopBridgeBody.tsx
new file mode 100644
index 000000000000..08164f118939
--- /dev/null
+++ b/frontend/src/scenes/code-canvas/QuillDesktopBridgeBody.tsx
@@ -0,0 +1,45 @@
+import { IconLaptop } from '@posthog/icons'
+import { Button, Heading, Text } from '@posthog/quill'
+
+import { LinkPrimitive } from 'lib/lemon-ui/Link'
+
+import { desktopBridgeDescription, openInDesktop } from './desktopBridge'
+import type { DesktopBridgeBodyProps } from './DesktopBridgeBody'
+
+/** The quill view of `DesktopBridgeBody`, for visitors on the `today-rail-nav` redesign. */
+export function QuillDesktopBridgeBody({ subject, deepLink, webUrl }: DesktopBridgeBodyProps): JSX.Element {
+ return (
+ <div data-quill className="flex flex-col items-center gap-4 text-center max-w-lg mx-auto">
+ <IconLaptop className="text-5xl shrink-0" />
+ <div className="flex flex-col gap-2">
+ <Heading size="xl" render={<h2 className="m-0" />}>
+ Opening in PostHog Desktop…
+ </Heading>
+ <Text size="xs" variant="muted" render={<p className="m-0" />}>
+ {desktopBridgeDescription(subject, !!webUrl)}
+ </Text>
+ </div>
+ <div className="flex flex-wrap justify-center gap-2">
+ {deepLink && (
+ <Button elevated variant="primary" size="lg" onClick={() => openInDesktop(deepLink)}>
+ Open in desktop app
+ </Button>
+ )}
+ {webUrl && (
+ <Button
+ elevated
+ variant="outline"
+ size="lg"
+ render={<LinkPrimitive to={webUrl} />}
+ data-attr="desktop-bridge-open-in-browser"
+ >
+ Open in browser
+ </Button>
+ )}
+ </div>
+ <Button variant="link" render={<LinkPrimitive to="https://posthog.com/desktop" target="_blank" />}>
+ Download PostHog Desktop
+ </Button>
+ </div>
+ )
+}
diff --git a/frontend/src/scenes/code-canvas/desktopBridge.ts b/frontend/src/scenes/code-canvas/desktopBridge.ts
new file mode 100644
index 000000000000..aa4e8b0ecd08
--- /dev/null
+++ b/frontend/src/scenes/code-canvas/desktopBridge.ts
@@ -0,0 +1,11 @@
+/** Sends the browser to a `posthog-code(-dev)://` deep link, which hands off to PostHog Desktop. */
+export function openInDesktop(deepLink: string): void {
+ window.location.href = deepLink
+}
+
+/** The explanation on a desktop bridge page. Both the Lemon and the quill view show it. */
+export function desktopBridgeDescription(subject: string, hasWebView: boolean): string {
+ return hasWebView
+ ? `${subject} should open in the PostHog Desktop app if it's installed. You can also open it in your browser.`
+ : `${subject} lives in the PostHog Desktop app. If it's installed, it should open automatically. If it didn't, use the button below, or download the app.`
+}
diff --git a/frontend/src/scenes/code-canvas/webPath.test.ts b/frontend/src/scenes/code-canvas/webPath.test.ts
new file mode 100644
index 000000000000..b3e4df7fcfd1
--- /dev/null
+++ b/frontend/src/scenes/code-canvas/webPath.test.ts
@@ -0,0 +1,11 @@
+import { webPath } from './webPath'
+
+describe('webPath', () => {
+ it.each([
+ ['a project prefix', '/project/123/code/canvas/ch-1/c-1', '/project/123/canvases/c-1'],
+ ['no project', '/code/canvas/ch-1/c-1', '/canvases/c-1'],
+ ['a project that is not an id', '/project/@current/code/canvas/ch-1/c-1', '/canvases/c-1'],
+ ])('builds the web path for a link with %s', (_, linkPathname, expected) => {
+ expect(webPath(linkPathname, '/canvases/c-1')).toBe(expected)
+ })
+})
diff --git a/frontend/src/scenes/code-canvas/webPath.ts b/frontend/src/scenes/code-canvas/webPath.ts
new file mode 100644
index 000000000000..311323cd5b9d
--- /dev/null
+++ b/frontend/src/scenes/code-canvas/webPath.ts
@@ -0,0 +1,12 @@
+import { getProjectIdentifierInPath } from 'lib/utils/kea-router'
+import { urls } from 'scenes/urls'
+
+/**
+ * The web app path for an item a share link points at. The link's `/project/<id>/` prefix names
+ * the project that owns the item, because the visitor's current project can be a different one.
+ * Links without a project fall back to the current project.
+ */
+export function webPath(linkPathname: string, path: string): string {
+ const projectId = getProjectIdentifierInPath(linkPathname)
+ return projectId && /^\d+$/.test(projectId) ? urls.project(projectId, path) : path
+}
diff --git a/posthog/api/test/test_comments.py b/posthog/api/test/test_comments.py
index 287748074c9c..fea4d8f9d167 100644
--- a/posthog/api/test/test_comments.py
+++ b/posthog/api/test/test_comments.py
@@ -254,7 +254,7 @@ class TestComments(APIBaseTest, QueryMatchingTest):
content="Canvas created",
payload={
"canvas_name": "Research canvas",
- "canvas_url": f"https://app.posthog.com/code/canvas/channel/{canvas_id}",
+ "canvas_url": f"https://app.posthog.com/project/{self.team.id}/code/canvas/channel/{canvas_id}",
},
)
root = Comment.objects.create(
diff --git a/products/canvas/backend/presentation/serializers.py b/products/canvas/backend/presentation/serializers.py
index 87c0de21a51f..c82ecdea3e92 100644
--- a/products/canvas/backend/presentation/serializers.py
+++ b/products/canvas/backend/presentation/serializers.py
@@ -41,7 +41,9 @@ _CANVAS_URL_HELP_TEXT = (
def canvas_url(canvas: CanvasRecord) -> str:
# The same shape the thread-message announcements use; the route deep-links
- # into the desktop app and renders in the web app.
+ # into the desktop app and renders in the web app. This URL has no
+ # `/project/<id>/` prefix because released desktop apps read it, and their
+ # share link parser only matches `/code/canvas/<channel>/<canvas>`.
return f"{settings.SITE_URL}/code/canvas/{canvas.channel_id}/{canvas.id}"
diff --git a/products/desktop/packages/ui/src/utils/posthogLinks.test.ts b/products/desktop/packages/ui/src/utils/posthogLinks.test.ts
index b0e3e587e8e3..6461a7ad9a49 100644
--- a/products/desktop/packages/ui/src/utils/posthogLinks.test.ts
+++ b/products/desktop/packages/ui/src/utils/posthogLinks.test.ts
@@ -14,11 +14,17 @@ vi.mock("@posthog/ui/utils/urls", () => ({
}));
describe("canvasShareUrl", () => {
- it("builds an https /code/canvas link with encoded ids", () => {
- expect(canvasShareUrl("chan/1", "dash 2", "us")).toBe(
- "https://us.posthog.com/code/canvas/chan%2F1/dash%202",
- );
- });
+ it.each([
+ [null, "https://us.posthog.com/code/canvas/chan%2F1/dash%202"],
+ [123, "https://us.posthog.com/project/123/code/canvas/chan%2F1/dash%202"],
+ ])(
+ "builds an https /code/canvas link for project %s",
+ (projectId, expected) => {
+ expect(
+ canvasShareUrl("chan/1", "dash 2", { projectId, cloudRegion: "us" }),
+ ).toBe(expected);
+ },
+ );
});
describe("inboxReportUrl", () => {
@@ -77,6 +83,16 @@ describe("parseShareLink", () => {
"https://us.posthog.com/code/channel/chan1/tasks/task1",
{ kind: "channel", channelId: "chan1", taskId: "task1" },
],
+ [
+ "canvas link with a project prefix",
+ "https://us.posthog.com/project/2/code/canvas/chan1/dash1",
+ { kind: "canvas", channelId: "chan1", dashboardId: "dash1" },
+ ],
+ [
+ "channel thread link with a project prefix",
+ "https://us.posthog.com/project/2/code/channel/chan1/tasks/task1",
+ { kind: "channel", channelId: "chan1", taskId: "task1" },
+ ],
])("parses a %s", (_label, href, expected) => {
expect(parseShareLink(href)).toEqual(expected);
});
@@ -95,6 +111,10 @@ describe("parseShareLink", () => {
"a channel thread link with a malformed tail",
"https://us.posthog.com/code/channel/chan1/foo/task1",
],
+ [
+ "a project prefix that is not an id",
+ "https://us.posthog.com/project/abc/code/canvas/chan1/dash1",
+ ],
["a malformed url", "not a url"],
])("returns null for %s", (_label, href) => {
expect(parseShareLink(href)).toBeNull();
diff --git a/products/desktop/packages/ui/src/utils/posthogLinks.ts b/products/desktop/packages/ui/src/utils/posthogLinks.ts
index 06290a4e1fbb..029b795bdd70 100644
--- a/products/desktop/packages/ui/src/utils/posthogLinks.ts
+++ b/products/desktop/packages/ui/src/utils/posthogLinks.ts
@@ -121,41 +121,49 @@ export function supportTicketUrl(
);
}
+/** `/project/<id>` for a share link, so the web interstitial can open the item in its own project. */
+function projectPrefix(overrides?: LinkOverrides): string {
+ const projectId = resolveProjectId(overrides?.projectId);
+ return projectId ? `/project/${projectId}` : "";
+}
+
/**
* The shareable https link for a canvas (a dashboard inside a channel):
- * `<instance>/code/canvas/<channelId>/<dashboardId>`. Opening it in a browser
- * hits a web interstitial that deep-links into the desktop app (or offers the
- * download), so the link works for anyone — app installed or not. Not
- * project-scoped: the ids are globally-unique desktop file-system row ids. The
- * inbound desktop side lives in `CanvasLinkService` / `useCanvasDeepLink`.
+ * `<instance>/project/<id>/code/canvas/<channelId>/<dashboardId>`. Opening it in a
+ * browser hits a web interstitial that deep-links into the desktop app (or offers
+ * the download), so the link works for anyone — app installed or not. The ids are
+ * globally-unique desktop file-system row ids; the project prefix only tells the
+ * interstitial which project to open the web canvas in. The inbound desktop side
+ * lives in `CanvasLinkService` / `useCanvasDeepLink`.
*/
export function canvasShareUrl(
channelId: string,
dashboardId: string,
- regionOverride?: CloudRegion | null,
+ overrides?: LinkOverrides,
): string | null {
return getPostHogUrl(
- `/code/canvas/${encodeURIComponent(channelId)}/${encodeURIComponent(dashboardId)}`,
- regionOverride,
+ `${projectPrefix(overrides)}/code/canvas/${encodeURIComponent(channelId)}/${encodeURIComponent(dashboardId)}`,
+ overrides?.cloudRegion,
);
}
/**
* The shareable https link for a channel — or a thread (channel-filed task)
- * inside it: `<instance>/code/channel/<channelId>[/tasks/<taskId>]`. Opening
- * it in a browser hits a web interstitial that deep-links into the desktop app
- * (or offers the download), so the link works for anyone — app installed or
- * not. Not project-scoped: the ids are globally-unique row ids. The inbound
+ * inside it: `<instance>/project/<id>/code/channel/<channelId>[/tasks/<taskId>]`.
+ * Opening it in a browser hits a web interstitial that deep-links into the
+ * desktop app (or offers the download), so the link works for anyone — app
+ * installed or not. The ids are globally-unique row ids; the project prefix only
+ * tells the interstitial which project to open the web space in. The inbound
* desktop side lives in `ChannelLinkService` / `useChannelDeepLink`.
*/
export function channelShareUrl(
channelId: string,
taskId?: string,
+ overrides?: LinkOverrides,
): string | null {
- const base = `/code/channel/${encodeURIComponent(channelId)}`;
- return getPostHogUrl(
- taskId ? `${base}/tasks/${encodeURIComponent(taskId)}` : base,
- );
+ const base = `${projectPrefix(overrides)}/code/channel/${encodeURIComponent(channelId)}`;
+ const path = taskId ? `${base}/tasks/${encodeURIComponent(taskId)}` : base;
+ return getPostHogUrl(path, overrides?.cloudRegion);
}
/**
@@ -225,6 +233,16 @@ function decodePathSegments(pathname: string): string[] {
});
}
+/**
+ * A share link names its project with a `/project/<id>/` prefix, and links from
+ * before that have none. The route is the same either way, so drop the prefix.
+ */
+function withoutProjectPrefix(segments: string[]): string[] {
+ return segments[0] === "project" && /^\d+$/.test(segments[1] ?? "")
+ ? segments.slice(2)
+ : segments;
+}
+
function matchRoute(
segments: string[],
route: ShareLinkRoute,
@@ -251,7 +269,7 @@ export function parseShareLink(href: string): ShareLinkTarget | null {
}
if (!posthogHosts().has(url.host)) return null;
- const segments = decodePathSegments(url.pathname);
+ const segments = withoutProjectPrefix(decodePathSegments(url.pathname));
for (const route of SHARE_LINK_ROUTES) {
const target = matchRoute(segments, route);
if (target) return target;
diff --git a/products/tasks/backend/logic/services/task_comments.py b/products/tasks/backend/logic/services/task_comments.py
index 03c5dddaada4..ab019a47b061 100644
--- a/products/tasks/backend/logic/services/task_comments.py
+++ b/products/tasks/backend/logic/services/task_comments.py
@@ -1,6 +1,7 @@
from base64 import urlsafe_b64decode, urlsafe_b64encode
from collections.abc import Callable, Sequence
from datetime import datetime
+from urllib.parse import urlsplit
from uuid import UUID
from django.db.models import Count, Q, QuerySet
@@ -164,6 +165,13 @@ def _canvas_comments(team_id: int, canvas_id: UUID) -> QuerySet[Comment]:
)
+def _canvas_id_from_url(canvas_url: object) -> str:
+ # Read the id from the path only, so a query or fragment on the URL never becomes part of it.
+ if not isinstance(canvas_url, str):
+ return ""
+ return urlsplit(canvas_url).path.rstrip("/").rsplit("/", 1)[-1]
+
+
def _canvas_names(*, team_id: int, task_id: UUID, canvas_ids: Sequence[str]) -> dict[str, str]:
wanted = set(canvas_ids)
names: dict[str, str] = {}
@@ -176,7 +184,7 @@ def _canvas_names(*, team_id: int, task_id: UUID, canvas_ids: Sequence[str]) ->
.values_list("payload", flat=True)[:CANVAS_EVENT_LIMIT]
):
canvas_url = payload.get("canvas_url") if isinstance(payload, dict) else None
- canvas_id = canvas_url.rstrip("/").rsplit("/", 1)[-1] if isinstance(canvas_url, str) else ""
+ canvas_id = _canvas_id_from_url(canvas_url)
canvas_name = payload.get("canvas_name") if isinstance(payload, dict) else None
if canvas_id in wanted and isinstance(canvas_name, str) and canvas_name:
names.setdefault(canvas_id, canvas_name)
@@ -273,7 +281,7 @@ def list_artifacts(*, team_id: int, task_id: UUID) -> list[contracts.TaskArtifac
):
canvas_url = payload.get("canvas_url") if isinstance(payload, dict) else None
canvas_name = payload.get("canvas_name") if isinstance(payload, dict) else None
- canvas_id = canvas_url.rstrip("/").rsplit("/", 1)[-1] if isinstance(canvas_url, str) else ""
+ canvas_id = _canvas_id_from_url(canvas_url)
if canvas_id:
artifacts.setdefault(
("canvas", canvas_id),