Skip to content

Commit 8aea876

Browse files
committed
fix(files): don't let a zero-width first measurement consume the immediate resize slot
A hidden container reports zero width from the ResizeObserver; treating that as the initial measurement pushed the real first width onto the debounce path and delayed initial render.
1 parent 53d0c67 commit 8aea876

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

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

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ export const PdfViewerCore = memo(function PdfViewerCore({ source, filename }: P
7272
)
7373

7474
/**
75-
* The first measurement applies immediately so the document renders without
76-
* delay; subsequent ones (panel-divider drags) are debounced because every
77-
* pageWidth change makes pdf.js re-rasterise all page canvases — per-tick
78-
* updates during a drag would re-render the whole document continuously.
75+
* The first non-zero measurement applies immediately so the document renders
76+
* without delay (a hidden container reports zero width and must not consume
77+
* the immediate slot); subsequent ones (panel-divider drags) are debounced
78+
* because every pageWidth change makes pdf.js re-rasterise all page canvases
79+
* — per-tick updates during a drag would re-render the whole document
80+
* continuously.
7981
*/
8082
useEffect(() => {
8183
const container = containerRef.current
@@ -85,6 +87,7 @@ export const PdfViewerCore = memo(function PdfViewerCore({ source, filename }: P
8587
const observer = new ResizeObserver(([entry]) => {
8688
const { width } = entry.contentRect
8789
if (!hasMeasured) {
90+
if (width <= 0) return
8891
hasMeasured = true
8992
setContainerWidth(width)
9093
return

0 commit comments

Comments
 (0)