Skip to content

fix(images): fix stale images#5462

Merged
Sg312 merged 2 commits into
stagingfrom
fix/stale-images
Jul 7, 2026
Merged

fix(images): fix stale images#5462
Sg312 merged 2 commits into
stagingfrom
fix/stale-images

Conversation

@Sg312

@Sg312 Sg312 commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes stale image -- server would cache the api route for image serving so it would serve a stale image

Type of Change

  • Bug fix

Testing

Manual

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Jul 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 7, 2026 1:51am

Request Review

@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes stale-image display when a workspace file is overwritten in-place (same storage key). Two complementary changes together close the bug.

  • image-preview.tsx: appends a ?v=<timestamp> query param derived from file.updatedAt (falling back to file.size) to the serve URL, ensuring each distinct write produces a distinct URL and bypasses the browser cache.
  • next.config.ts: tightens the static-asset Cache-Control source pattern from /:all*(svg|jpg|…) to /((?!api/).*\\.(?:svg|jpg|…)), preventing the public, max-age=86400 header from being applied to /api/files/serve/* endpoints — which would otherwise cause proxies/browsers to ignore the version query parameter.

Confidence Score: 5/5

Both changes are narrow, well-scoped fixes; no existing functionality is removed and the caching behaviour is strictly improved.

The URL-versioning logic correctly handles the common case (valid ISO date string from JSON) and the edge case (missing/invalid date falls back to file size). The regex change in next.config.ts accurately excludes /api/ prefixed paths from the static-asset cache rule without disturbing any other route. The two changes are complementary and together close the stale-image window without side effects on other routes.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/image-preview.tsx Adds a cache-busting version parameter derived from file.updatedAt (with file.size as a fallback) to prevent stale images when a file is overwritten in-place.
apps/sim/next.config.ts Narrows the long-lived Cache-Control header pattern to exclude /api/* routes, preventing API file-serve endpoints from receiving static-asset-style caching headers that would have overridden versioned cache-busting.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Browser
    participant NextHeaders as Next.js Headers Middleware
    participant API as /api/files/serve/:key

    Note over Browser,API: Before fix — file overwrite causes stale image

    Browser->>API: GET /api/files/serve/img.jpg (no version)
    NextHeaders-->>Browser: "Cache-Control: public, max-age=86400 (matched old pattern)"
    Browser->>Browser: Cache response for 24h

    Note over Browser,API: After fix — version param + API excluded from static cache

    Browser->>API: "GET /api/files/serve/img.jpg?v=1720000000000"
    Note over NextHeaders: /((?!api/)...) does NOT match /api/ prefix
    API-->>Browser: 200 OK (no long-lived max-age)
    Browser->>Browser: "Caches by full URL including ?v="

    Note over Browser,API: File overwritten — updatedAt changes

    Browser->>API: "GET /api/files/serve/img.jpg?v=1720001234567"
    API-->>Browser: 200 OK — fresh bytes served
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Browser
    participant NextHeaders as Next.js Headers Middleware
    participant API as /api/files/serve/:key

    Note over Browser,API: Before fix — file overwrite causes stale image

    Browser->>API: GET /api/files/serve/img.jpg (no version)
    NextHeaders-->>Browser: "Cache-Control: public, max-age=86400 (matched old pattern)"
    Browser->>Browser: Cache response for 24h

    Note over Browser,API: After fix — version param + API excluded from static cache

    Browser->>API: "GET /api/files/serve/img.jpg?v=1720000000000"
    Note over NextHeaders: /((?!api/)...) does NOT match /api/ prefix
    API-->>Browser: 200 OK (no long-lived max-age)
    Browser->>Browser: "Caches by full URL including ?v="

    Note over Browser,API: File overwritten — updatedAt changes

    Browser->>API: "GET /api/files/serve/img.jpg?v=1720001234567"
    API-->>Browser: 200 OK — fresh bytes served
Loading

Reviews (1): Last reviewed commit: "Fix comment" | Re-trigger Greptile

@Sg312 Sg312 merged commit 11be2a3 into staging Jul 7, 2026
18 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/stale-images branch July 7, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant