Skip to content

Commit 3c715be

Browse files
committed
fix(images): fix stale images
1 parent fb3f95d commit 3c715be

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/image-preview.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import { ZoomablePreview } from './zoomable-preview'
77

88
export const ImagePreview = memo(function ImagePreview({ file }: { file: WorkspaceFileRecord }) {
99
const source = useFileContentSource()
10-
const serveUrl = source.buildUrl(file.key)
10+
// Version the URL on updatedAt: overwrites keep the same storage key, so an unversioned
11+
// URL would resolve to a previously cached copy instead of the rewritten bytes.
12+
const serveUrl = source.buildUrl(file.key, {
13+
version: Number(new Date(file.updatedAt)) || file.size,
14+
})
1115

1216
return (
1317
<ZoomablePreview className='flex flex-1' contentClassName='h-full w-full'>

apps/sim/next.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,12 @@ const nextConfig: NextConfig = {
177177
async headers() {
178178
return [
179179
{
180-
source: '/:all*(svg|jpg|jpeg|png|gif|ico|webp|avif|woff|woff2|ttf|eot)',
180+
// Static assets only — the (?!api/) guard keeps this off API routes. Without it,
181+
// /api/files/serve/<key>.png matched too, and Next drops a route handler's own
182+
// Cache-Control when the config rule already set one, so in-place file overwrites
183+
// (same storage key, e.g. copilot image/chart regeneration) served day-stale bytes
184+
// from the browser cache.
185+
source: '/((?!api/).*\\.(?:svg|jpg|jpeg|png|gif|ico|webp|avif|woff|woff2|ttf|eot))',
181186
headers: [
182187
{
183188
key: 'Cache-Control',

0 commit comments

Comments
 (0)