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.

fix(canvas): open canvas share links in the web app (#121370)

Adam Leith983d4c467d97
diff --git a/frontend/src/scenes/code-canvas/CodeCanvasLink.test.tsx b/frontend/src/scenes/code-canvas/CodeCanvasLink.test.tsx
index f691d5ca1843..5b995166a0ac 100644
--- a/frontend/src/scenes/code-canvas/CodeCanvasLink.test.tsx
+++ b/frontend/src/scenes/code-canvas/CodeCanvasLink.test.tsx
@@ -1,22 +1,22 @@
import '@testing-library/jest-dom'
-import { cleanup, render, screen } from '@testing-library/react'
+import { cleanup, render } 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', () => {
+ const replace = jest.fn()
+
beforeEach(() => {
- // jsdom refuses a real navigation, so stand in a location whose href we can read back.
+ replace.mockReset()
+ // jsdom refuses a real navigation, so stand in a location whose replace we can read back.
Object.defineProperty(window, 'location', {
configurable: true,
- value: { ...window.location, href: '' },
+ value: { ...window.location, replace },
})
initKeaTests()
})
@@ -30,10 +30,9 @@ describe('CodeCanvasLink', () => {
[
'a project-scoped link, in that project',
'/project/7/code/canvas/channel-1/canvas-1',
- /\/project\/7\/canvases\/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 })
+ ])('opens the canvas in the web app for %s', (_, path, expectedPath) => {
router.actions.push(path)
render(
<Provider>
@@ -41,21 +40,6 @@ describe('CodeCanvasLink', () => {
</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()
+ expect(replace).toHaveBeenCalledWith(expect.stringMatching(expectedPath))
})
})
diff --git a/frontend/src/scenes/code-canvas/CodeCanvasLink.tsx b/frontend/src/scenes/code-canvas/CodeCanvasLink.tsx
index 8a2ba7fb3d7c..72b74a0b5366 100644
--- a/frontend/src/scenes/code-canvas/CodeCanvasLink.tsx
+++ b/frontend/src/scenes/code-canvas/CodeCanvasLink.tsx
@@ -2,13 +2,10 @@ 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 { SpinnerOverlay } from 'lib/lemon-ui/Spinner/Spinner'
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 {
@@ -24,38 +21,24 @@ export const scene: SceneExport<CodeCanvasLinkProps> = {
}),
}
-function canvasDeepLink(channelId: string, dashboardId: string): string {
- return `${DESKTOP_SCHEME}://canvas/${encodeURIComponent(channelId)}/${encodeURIComponent(dashboardId)}`
-}
-
/**
- * Public, unauthenticated bridge for desktop-app "canvas" share links
- * (`/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. Visitors who can open canvases on the web also
- * get a link to the canvas in the browser.
+ * Public entry point for canvas share links (`/code/canvas/<channelId>/<dashboardId>`).
+ * The link shape stays because released desktop apps parse it, but in the browser it
+ * always opens the canvas in the web app.
*/
-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')
+export function CodeCanvasLink({ dashboardId }: CodeCanvasLinkProps): JSX.Element {
const { location } = useValues(router)
- const webUrl = webCanvasEnabled && dashboardId ? webPath(location.pathname, urls.canvasDetail(dashboardId)) : null
+ const webUrl = dashboardId ? webPath(location.pathname, urls.canvasDetail(dashboardId)) : null
useEffect(() => {
- if (deepLink) {
- window.location.href = deepLink
+ if (webUrl) {
+ // A full page load, because a client-side route change skips the server login gate
+ // and a signed-out visitor would see a blank page instead of the login page.
+ window.location.replace(webUrl)
}
- }, [deepLink])
+ }, [webUrl])
- return (
- <BridgePage view="code-canvas-link">
- <DesktopBridgeBody subject="This canvas" deepLink={deepLink} webUrl={webUrl} />
- </BridgePage>
- )
+ return <SpinnerOverlay sceneLevel />
}
export default CodeCanvasLink