@@ -160,7 +160,6 @@ import { HighlightedCodeLines } from "./chat/HighlightedCodeLines";
160160import { RenderErrorBoundary } from "./RenderErrorBoundary" ;
161161import { MermaidDiagram } from "./chat/MermaidDiagram" ;
162162import { useTheme } from "../hooks/useTheme" ;
163- import { useWorkspaceMutationRefresh } from "../hooks/useWorkspaceMutationRefresh" ;
164163import { getClientSettings , useClientSettings } from "../hooks/useSettings" ;
165164import {
166165 chatMarkdownClipboardPayload ,
@@ -1584,17 +1583,40 @@ export const ChatMarkdownAssetImage = memo(function ChatMarkdownAssetImage(props
15841583 const refreshAssetUrl = useAssetUrlRefresh ( props . environmentId , props . resource ) ;
15851584 const connectionReady = usePreparedConnection ( props . environmentId ) . _tag === "Some" ;
15861585 const resource = props . resource ;
1587- // Only file previews pass a mutation id. Chat markdown must not re-mint URLs,
1588- // and a preview must refresh once the connection is ready, so an edit made
1589- // while offline still replaces a cached failure or stale signed URL.
1590- useWorkspaceMutationRefresh ( {
1591- enabled : props . workspaceMutationId !== undefined && connectionReady ,
1592- mutationId : props . workspaceMutationId ?? null ,
1593- resourceKey : JSON . stringify ( [ props . environmentId , resource ] ) ,
1594- refresh : ( ) => {
1595- void refreshAssetUrl ( ) . catch ( ( ) => undefined ) ;
1596- } ,
1597- } ) ;
1586+ const refreshToken = JSON . stringify ( [ props . environmentId , resource , props . workspaceMutationId ] ) ;
1587+ const handledRefreshToken = useRef < string | null | undefined > ( undefined ) ;
1588+ const assetLoading = assetUrl . _tag === "Loading" || assetUrl . waiting === true ;
1589+ useEffect ( ( ) => {
1590+ if ( ! connectionReady ) {
1591+ handledRefreshToken . current = null ;
1592+ return ;
1593+ }
1594+ if (
1595+ props . workspaceMutationId === undefined ||
1596+ props . kind === "video" ||
1597+ ( resource . _tag !== "media-file" && resource . _tag !== "workspace-file" ) ||
1598+ handledRefreshToken . current === refreshToken
1599+ ) {
1600+ return ;
1601+ }
1602+ if ( assetLoading ) {
1603+ // Only the initial mount shares a pending request; edits and reconnects need a new one.
1604+ if ( handledRefreshToken . current === undefined ) {
1605+ handledRefreshToken . current = refreshToken ;
1606+ }
1607+ return ;
1608+ }
1609+ handledRefreshToken . current = refreshToken ;
1610+ void refreshAssetUrl ( ) . catch ( ( ) => undefined ) ;
1611+ } , [
1612+ assetLoading ,
1613+ connectionReady ,
1614+ props . kind ,
1615+ props . workspaceMutationId ,
1616+ refreshAssetUrl ,
1617+ refreshToken ,
1618+ resource . _tag ,
1619+ ] ) ;
15981620 const path =
15991621 resource . _tag === "media-file"
16001622 ? resource . path
0 commit comments