Skip to content

Commit 3c555af

Browse files
committed
Fix PPTX cache key stability and attribute-order-independent dimension parsing
1 parent 5712ac4 commit 3c555af

File tree

1 file changed

+11
-8
lines changed
  • apps/sim/app/workspace/[workspaceId]/files/components/file-viewer

1 file changed

+11
-8
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,8 @@ function ImagePreview({ file }: { file: WorkspaceFileRecord }) {
436436

437437
const pptxSlideCache = new Map<string, string[]>()
438438

439-
function pptxCacheKey(fileId: string, dataUpdatedAt: number): string {
440-
return `${fileId}:${dataUpdatedAt}`
439+
function pptxCacheKey(fileId: string, byteLength: number): string {
440+
return `${fileId}:${byteLength}`
441441
}
442442

443443
function pptxCacheSet(key: string, slides: string[]): void {
@@ -492,11 +492,15 @@ async function getPptxRenderSize(
492492
const presentationXml = await zip.file('ppt/presentation.xml')?.async('text')
493493
if (!presentationXml) return fallback
494494

495-
const match = presentationXml.match(/<p:sldSz[^>]*cx="(\d+)"[^>]*cy="(\d+)"/)
496-
if (!match) return fallback
495+
const tagMatch = presentationXml.match(/<p:sldSz\s[^>]+>/)
496+
if (!tagMatch) return fallback
497+
const tag = tagMatch[0]
498+
const cxMatch = tag.match(/\bcx="(\d+)"/)
499+
const cyMatch = tag.match(/\bcy="(\d+)"/)
500+
if (!cxMatch || !cyMatch) return fallback
497501

498-
const cx = Number(match[1])
499-
const cy = Number(match[2])
502+
const cx = Number(cxMatch[1])
503+
const cy = Number(cyMatch[1])
500504
if (!Number.isFinite(cx) || !Number.isFinite(cy) || cx <= 0 || cy <= 0) return fallback
501505

502506
const aspectRatio = cx / cy
@@ -532,10 +536,9 @@ function PptxPreview({
532536
data: fileData,
533537
isLoading: isFetching,
534538
error: fetchError,
535-
dataUpdatedAt,
536539
} = useWorkspaceFileBinary(workspaceId, file.id, file.key)
537540

538-
const cacheKey = pptxCacheKey(file.id, dataUpdatedAt)
541+
const cacheKey = pptxCacheKey(file.id, fileData?.byteLength ?? 0)
539542
const cached = pptxSlideCache.get(cacheKey)
540543

541544
const [slides, setSlides] = useState<string[]>(cached ?? [])

0 commit comments

Comments
 (0)