77 SpinnerGapIcon ,
88 WarningIcon ,
99} from "@phosphor-icons/react" ;
10+ import { publishedCanvasBuild } from "@posthog/core/canvas/canvasBuildSchemas" ;
1011import type { CanvasAnalyticsConfig } from "@posthog/core/canvas/freeformSchemas" ;
1112import { useHostTRPC } from "@posthog/host-router/react" ;
1213import {
@@ -22,6 +23,7 @@ import {
2223 isCanvasGenerating ,
2324 isCanvasGenerationRunning ,
2425} from "@posthog/ui/features/canvas/freeform/canvasGenerationStatus" ;
26+ import { useCanvasBuilds } from "@posthog/ui/features/canvas/hooks/useCanvasBuilds" ;
2527import { useChannels } from "@posthog/ui/features/canvas/hooks/useChannels" ;
2628import { useCanvasChatPanelStore } from "@posthog/ui/features/canvas/stores/canvasChatPanelStore" ;
2729import {
@@ -44,6 +46,7 @@ import { useQuery, useQueryClient } from "@tanstack/react-query";
4446import { Link } from "@tanstack/react-router" ;
4547import { AnimatePresence , motion } from "framer-motion" ;
4648import { useCallback , useMemo , useRef , useState } from "react" ;
49+ import { BuiltCanvas } from "./BuiltCanvas" ;
4750import { CanvasBuildStatus } from "./CanvasBuildStatus" ;
4851import { CanvasFramePlaceholder } from "./CanvasFramePlaceholder" ;
4952import { CanvasGenerateHero } from "./CanvasGenerateHero" ;
@@ -237,7 +240,11 @@ export function FreeformCanvasView({
237240 // Deriving from the record rather than waiting on the seed also means a seed
238241 // that never runs can't strand the canvas on a spinner.
239242 const renderCode = code || dashboard ?. code || "" ;
240- const showCanvas = ! ! renderCode ;
243+ const { lifecycle } = useCanvasBuilds ( dashboardId ) ;
244+ const artifactUrl = lifecycle
245+ ? publishedCanvasBuild ( lifecycle ) ?. artifactUrl
246+ : null ;
247+ const showCanvas = ! ! artifactUrl || ! ! renderCode ;
241248 // `isGenerating` keys off the effective task (the optimistic bridge right after
242249 // submit, then the polled record) and short-circuits on a terminal run — so a
243250 // failed/cancelled run can't strand the canvas body on the spinner.
@@ -377,15 +384,25 @@ export function FreeformCanvasView({
377384 // this placeholder just reserves the viewport box and owns scroll via
378385 // the host's overlay, so the canvas survives navigation without a reload.
379386 < Box className = "h-full w-full" >
380- < CanvasFramePlaceholder
381- dashboardId = { dashboardId }
382- code = { renderCode }
383- analytics = { analytics }
384- onDataRequest = { onDataRequest }
385- onError = { onError }
386- onRendered = { onRendered }
387- onNavigate = { onNavigate }
388- />
387+ { artifactUrl ? (
388+ < BuiltCanvas
389+ artifactUrl = { artifactUrl }
390+ onDataRequest = { onDataRequest }
391+ onError = { onError }
392+ onRendered = { onRendered }
393+ onNavigate = { onNavigate }
394+ />
395+ ) : (
396+ < CanvasFramePlaceholder
397+ dashboardId = { dashboardId }
398+ code = { renderCode }
399+ analytics = { analytics }
400+ onDataRequest = { onDataRequest }
401+ onError = { onError }
402+ onRendered = { onRendered }
403+ onNavigate = { onNavigate }
404+ />
405+ ) }
389406 </ Box >
390407 ) : (
391408 < ScrollArea className = "h-full" >
0 commit comments