Skip to content

Commit f2fe99e

Browse files
fix(files): version public viewer caches by file updatedAt so edits aren't stale
1 parent e0fbd43 commit f2fe99e

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

apps/sim/app/f/[token]/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default async function PublicFilePage({ params }: PublicFilePageProps) {
3030
name={file.originalName}
3131
type={file.contentType}
3232
size={file.size}
33+
version={file.updatedAt.getTime()}
3334
workspaceName={workspaceName}
3435
ownerName={ownerName}
3536
/>

apps/sim/app/f/[token]/public-file-view.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ interface PublicFileViewProps {
1515
name: string
1616
type: string
1717
size: number
18+
/** Content version (the file's `updatedAt`, epoch ms) — busts the viewer's caches when the file changes. */
19+
version: number
1820
workspaceName: string | null
1921
ownerName: string | null
2022
}
@@ -24,6 +26,7 @@ export function PublicFileView({
2426
name,
2527
type,
2628
size,
29+
version,
2730
workspaceName,
2831
ownerName,
2932
}: PublicFileViewProps) {
@@ -35,23 +38,26 @@ export function PublicFileView({
3538

3639
// The public viewer reuses the in-app FileViewer; the content source seam swaps
3740
// the auth-gated workspace serve URL for the token-scoped public endpoint, and a
38-
// synthetic record carries the metadata the renderers/query keys need.
41+
// synthetic record carries the metadata the renderers/query keys need. `key` and
42+
// `updatedAt` fold in the content version so the React Query caches (keyed on the
43+
// storage key + `updatedAt`) refetch when the shared file changes — even when its
44+
// size is unchanged.
3945
const source = useMemo<FileContentSource>(() => ({ buildUrl: () => contentUrl }), [contentUrl])
4046
const file = useMemo<WorkspaceFileRecord>(
4147
() => ({
4248
id: token,
4349
workspaceId: token,
4450
name,
45-
key: token,
51+
key: `${token}@${version}`,
4652
path: contentUrl,
4753
size,
4854
type,
4955
uploadedBy: '',
5056
folderId: null,
51-
uploadedAt: new Date(0),
52-
updatedAt: new Date(0),
57+
uploadedAt: new Date(version),
58+
updatedAt: new Date(version),
5359
}),
54-
[token, name, type, size, contentUrl]
60+
[token, name, type, size, version, contentUrl]
5561
)
5662

5763
return (

0 commit comments

Comments
 (0)